绕过 PHP 安全模式来写入服务器。 是否可以?
由于服务器打开了安全模式,并且在不同用户下创建目录,因此我遇到了以下问题:
- 我将脚本上传到服务器,它显示为属于“user1”。 它所做的就是在创建新用户时创建一个新目录,以便可以在其中存储文件。
- 新目录已创建,但属于“apache”用户。
- 'user1' 和 'apache' 是不同的用户; 并且安全模式已开启。 因此 php 脚本无法写入新创建的目录。
- 现在我有一个问题!
一种解决方案是关闭安全模式。 此外,一位同事建议可以更改一些设置,以确保目录与脚本位于同一用户下。 所以我想看看后者是否可以完成。
但我不得不问。 有针对我的问题的编程解决方案吗?
我倾向于“不”,因为安全模式是为了在 php 级别解决这个问题而实现的。 此外,实际问题可能看起来像是在不同用户下创建的目录,因此程序性修复可能只是一个创可贴修复。
I have got the following problem since the server has safe mode turned on, and directories are being created under different users:
- I upload my script to the server, it shows as belonging to 'user1'. All it is doing is making a new directory when a new user is created so it can store files in it.
- New directory is created, but it belongs to 'apache' user.
- 'user1' and 'apache' are different users; and safe mode is turned on. So the php script cannot write to that newly created directory.
- Now I have a problem!
One solution is to turn off safe mode. Also, a coworker suggested that there are settings that can be changed to ensure the directories are under the same user as the script. So I am looking to see if latter can be done.
But I have to ask. Is there a programatical solution for my problem?
I am leaning to a 'no', as safe mode was implemented to solve it at the php level. Also the actual problem may seem like the directory being created under a different user, so a programatic fix might just be a band-aid fix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用了这个解决方法:
您可以使用适当的权限通过 FTP 创建目录,而不是 php mkdir。
I've used this workaround:
instead of php mkdir you can create directories by FTP with proper rights.
您可以通过 .htaccess 文件(如果在 Apache 上)关闭特定目录的安全模式。
您可能需要让您的托管提供商在 httpd.conf 中为您进行此更改。
You might be able to turn safe mode off for a specific directory via a .htaccess file (if on Apache).
You might need to get your hosting provider to make this change for you though in the httpd.conf.
我在将上传目录的组位设置为粘性方面取得了一些成功。
然后 PHP 可以在其中创建目录并写入内容。
http://en.wikipedia.org/wiki/Setuid#setuid_and_setgid_on_directories
chmod g+s 目录
I have had some success with setting the group bit of the upload directory to sticky.
PHP can then create directories inside it and write to it.
http://en.wikipedia.org/wiki/Setuid#setuid_and_setgid_on_directories
chmod g+s directory