Unix 上的 Apache+PHP 写入权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2262327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:46:40  来源:igfitidea点击:

Apache+PHP write permissions on unix

phpapachefile-permissions

提问by Pavel Dubinin

I'm trying to launch PHP site with apache on fedora and I have a problem about writting permissions. It looks like apache does not have write permissions to some folders, but I canno understand why.

我正在尝试在 Fedora 上使用 apache 启动 PHP 站点,但我在写入权限方面遇到了问题。看起来 apache 对某些文件夹没有写权限,但我不明白为什么。

I've checked httpd.conf and it has group: apache, user: apache. I then made: chown -R apache:apache www and set 777 permissions to the folders, but it still says:

我检查了 httpd.conf,它有组:apache,用户:apache。然后我做了: chown -R apache:apache www 并为文件夹设置了 777 权限,但它仍然说:

Warning: file_put_contents(/var/www/public/temp.txt) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/public/newtest.php on line 8

警告:file_put_contents(/var/www/public/temp.txt) [function.file-put-contents]:无法打开流:第 8 行的 /var/www/public/newtest.php 中的权限被拒绝

Please advice.

请指教。

UPDATE: Btw, if I make "php newtest.php" from command line, the file temp.txt is created with group root and user root. It just doest not work from the browser.

更新:顺便说一句,如果我从命令行创建“php newtest.php”,文件 temp.txt 是使用组 root 和用户 root 创建的。它只是在浏览器中不起作用。

回答by symcbean

Warning: file_put_contents(/var/www/public/temp.txt) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/public/newtest.php on line 8

警告:file_put_contents(/var/www/public/temp.txt) [function.file-put-contents]:无法打开流:第 8 行的 /var/www/public/newtest.php 中的权限被拒绝

There is so much bad stuff here.

这里有很多不好的东西。

Lets start with the fact that you really want to keep httpd writeable files well away from your code - certainly in a seperate directory, preferably outside the document root altogether.

让我们从这样一个事实开始,即您确实想让 httpd 可写文件远离您的代码——当然是在一个单独的目录中,最好完全在文档根目录之外。

chown -R apache:apache www and set 777 permissions to the folders

chown -R apache:apache www 并为文件夹设置 777 权限

And did you check afterwards what the permissions actually were? BTW see also the point above - if you've made your entire website writeable by the everybody then you're just asking for trouble. You certainly chouldn't change BOTH the owner AND the permissions.

之后您是否检查过权限实际上是什么?顺便说一句,还请参见上面的观点 - 如果您已经让每个人都可以编写您的整个网站,那么您只是在自找麻烦。您当然不会更改所有者和权限。

Have you got SELinux enabled? (run sestatus as root). If so then you either need to disable it or learn how to configure it - but I'd recommend you get to grips with old-fashioned permissions first, then disable SELinux.

你启用了 SELinux 吗?(以 root 身份运行 sestatus)。如果是这样,那么您要么需要禁用它,要么学习如何配置它 - 但我建议您首先掌握老式权限,然后禁用 SELinux。

C.

C。

回答by Amad

make chmod 775 to newtest.php ;)

将 chmod 775 设为 newtest.php ;)

回答by Qwerty

ls -la /var/www/public

ls -la /var/www/public

Just to check :-)

只是为了检查:-)

回答by hurikhan77

I'd recommend switching apache to mod_itk as mpm and running the particular vhost with permissions of the owner document root directory and contained php scripts.

我建议将 apache 切换到 mod_itk 作为 mpm 并使用所有者文档根目录的权限运行特定的 vhost 并包含 php 脚本。