move_uploaded file:failed 打开流: /srv/http/upload 中的权限被拒绝。php

move_uploaded file:failed to open stream: Permission denied in /srv/http/upload.php

我正在尝试 运行 ArchLinux 上的服务器,我有 apache 和 PHP 运行ning 正常,但我无法使用 PHP 上传文件.我在 Whosebug 上看到过很多此类问题,我似乎已经使用了我找到的所有建议,但我仍然得到

failed to open stream: Permission denied in /srv/http/upload.php 

错误。

准确地说

Warning:  move_uploaded_file(): Unable to move '/tmp/phpZvJK1l' to '/home/administrator/SCRIPTS/tr/solution.cpp' in /srv/http/upload.php on line 20

我将 /tmp/、/home/administrator/SCRIPTS/tr 和 /srv/http 的权限设置为 777(我知道那不对,但我现在在本地工作,我想让它以某种方式工作) .

我也将这些目录的所有所有者都设置为http(即用户运行ning PHP),但是还是不行。

一些 PHP 配置不允许访问用户 docroot 目录之外的文件,因此您可能无法从 PHP 中访问 /tmp。尝试将文件上传到 /home/administrator 目录中的临时目录 - 最好是网络浏览器无法访问的目录(文档根目录的同级目录)。

授予 /tmp 目录权限:

sudo chmod 777 /tmp

作为 Arch 用户,我在处理 Web 项目时遇到了同样的问题。

我建议您查看 this 部分 Arch Wiki

User directories are available by default through http://localhost/~yourusername/ and show the contents of ~/public_html (this can be changed in /etc/httpd/conf/extra/httpd-userdir.conf).

所以你必须创建 ~/public_html 目录然后

You must make sure that your home directory permissions are set properly so that Apache can get there. Your home directory and ~/public_html must be executable for others ("rest of the world"):

$ chmod o+x ~
$ chmod o+x ~/public_html
$ chmod -R o+r ~/public_html

之后你不需要将你的文件放在 /srv/http/ 下你现在可以使用 ~/public_html 作为开发目录。