如何使用 chmod 或 .htaccess 停止 PHP 文件编辑父目录?
我允许人们使用我的服务器上的目录,但我不希望 PHP 文件或其他服务器端脚本编辑任何父目录,是否有人知道如何执行此操作以及是否可以使用 chmod 或 .htaccess。
我用谷歌搜索了它,但找不到任何东西,我认为我可能一直在寻找错误的东西。
I am allowing people to use a directory on my server but i don't want PHP files or other server side scripts editing any of the parent directories does anyone know how to do this and if it is possible with chmod or .htaccess.
I did google it but could not find anything i think i may have been looking for the wrong thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 open_basedir 指令将 PHP 脚本限制在其主目录和最终的额外目录中。这本身就非常有效。
使用强化的 php,因为这不需要任何成本,而且可以提供帮助。
使用 suPHP 让 PHP 脚本以文件所有者的身份执行(每个网站一个用户),并避免使用具有不良权限的文件,例如 777...suPHP 还可以允许您每个目录有一个 php.ini,这样一个人就愚蠢了要求不要破坏一切。
Mod_security 是一个很大的优点,但需要很好地使用和配置。
Use the open_basedir directive to confine your PHP scripts to their home directory and eventual extra directories. This is very efficient by itself.
Use hardened php because that costs nothing and it can help.
Use suPHP to have PHP scripts execute as the owner of the file (one user per website) and avoid using files with bad permissions such as 777... suPHP can also allow you to have one php.ini per directory so that one person's stupid requirement don't destroy everything.
Mod_security is a big plus but needs to be well used and configured.
只是不允许运行 PHP 脚本的用户更改父目录。使用与 PHP 用户不同的用户对父目录 drwxr-xr-x 进行 chmod。然后在子文件夹中授予必要的权限。
Just do not allow the user with whose credentials the PHP scripts are run to alter the parent directory. Chmod the parent directory drwxr-xr-x with a user different to the PHP user. Then give the necessary permissions in the subfolders.
您的意思是,您不希望他们能够更改您的 PHP 文件吗?
或者您不希望 PHP 程序能够更改此目录中的文件?
如果是第一个,请将文件的所有权设置为与访客使用
chown
登录时不同的所有者和组。然后在要保护的文件夹中执行chmod go-rwx *php
。这将使与您和其他任何人不在同一组的用户无法读取、执行或写入这些文件。如果是第二种情况,请将文件的所有权更改为您的网络服务器运行帐户以外的其他帐户(尝试
)。然后执行与上面相同的 chmod 命令。
Do you mean, you don't want them to be able to alter your PHP files?
Or you don't want the PHP programs to be able to alter files in this directory?
If it's the first, set the ownership of the files to a different owner and group than the guests are logging in with using
chown
. Then dochmod go-rwx *php
in the folder you want to protect. That will make it so users not in the same group as you + anyone else cannot read, execute or write to those files.If it's the second case, change the ownership of the files to something other than the account your webserver is running as (try
<?php passthru('whoami');?>
). Then do the same chmod command as above.