Heim  >  Artikel  >  php教程  >  上传文件的PHP脚本不工作的问题(目录权限问题)php-fpm+nginx

上传文件的PHP脚本不工作的问题(目录权限问题)php-fpm+nginx

WBOY
WBOYOriginal
2016-06-06 20:12:081164Durchsuche

我本来是想传一些文件到某台服务器上,但,由于一些防火墙策略的原因,该服务器只能通过HTTP 80端口访问,而不能直接SCP或FTP传到该服务器上。每次上传文件都是中转几次,颇为麻烦。 所以,我就写了一个PHP脚本部署到了该服务器上,之后我就可以通过脚本或者

我本来是想传一些文件到某台服务器上,但,由于一些防火墙策略的原因,该服务器只能通过HTTP 80端口访问,而不能直接SCP或FTP传到该服务器上。每次上传文件都是中转几次,颇为麻烦。
所以,我就写了一个PHP脚本部署到了该服务器上,之后我就可以通过脚本或者网页直接上传文件了。
本来是很简单的事情,不过由于一些问题,没有将文件上传并保存成功;后来仔细分析,才发现是进程读写目录的权限问题。(原来想着我已经将保存文件的目录的owner设置为nignx用户了,而nginx进程就是以nginx账号执行的)

服务器上我是用nginx+php-fpm来支撑我的PHP程序的,刚开始没注意到的是,php-fpm是默认已apache用户账号启动的,如下所示:

[qa@my-server html]$ ps -ef | grep php
qa         783 32549  0 16:42 pts/0    00:00:00 grep php
apache   27349 32434  0 Apr08 ?        00:02:11 php-fpm: pool www
apache   27429 32434  0 Apr08 ?        00:02:10 php-fpm: pool www
root     32434     1  0 Apr04 ?        00:00:44 php-fpm: master process (/etc/php-fpm.conf)
apache   32435 32434  0 Apr04 ?        00:02:11 php-fpm: pool www
apache   32436 32434  0 Apr04 ?        00:02:11 php-fpm: pool www
apache   32437 32434  0 Apr04 ?        00:02:11 php-fpm: pool www
apache   32438 32434  0 Apr04 ?        00:02:11 php-fpm: pool www
apache   32439 32434  0 Apr04 ?        00:02:11 php-fpm: pool www


为什么是Apache账号呢?查看php-fpm的配置文件,可知:在/etc/php-fpm.d/www.conf 中有如下配置:

?
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

将其改为nginx账号,如下:

user = nginx
group = nginx

然后让php-fpm进程重新加载配置文件即可,如下:

[root@my-server html]# service php-fpm reload    (或者 restart 重启)

不小心掉在php-fpm进程的权限这个坑里了,所以记录一下。

Original article: 上传文件的PHP脚本不工作的问题(目录权限问题)php-fpm+nginx

©2014 笑遍世界. All Rights Reserved.

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn