大网数据广告活动
服务器运维问答

php-fpm not running as user specified in pool

· 52CE 我爱测

I have an Ubuntu18.04 web server with nginx and php-fpm (7.2) installed. There are 6 pools, each with their own user and group: /etc/php/7.2/fpm# grep -r ^user * php.ini:user_dir = pool.d/dev3.website.com.conf:user = dev3_app poo…

问题原文

原帖链接 · jdog · CC BY-SA 4.0

I have an Ubuntu18.04 web server with nginx and php-fpm (7.2) installed.

There are 6 pools, each with their own user and group:

/etc/php/7.2/fpm# grep -r ^user * 
php.ini:user_dir =
pool.d/dev3.website.com.conf:user = dev3_app
pool.d/dev1.website.com.conf:user = dev1_app
pool.d/dev4.website.com.conf:user = dev4_app
pool.d/dev6.website.com.conf:user = dev6_app
pool.d/dev5.website.com.conf:user = dev5_app
pool.d/dev2.website.com.conf:user = dev2_app

/etc/php/7.2/fpm# grep -r ^group * 
pool.d/dev3.website.com.conf:group = dev3_app
pool.d/dev1.website.com.conf:group = dev1_app
pool.d/dev4.website.com.conf:group = dev4_app
pool.d/dev6.website.com.conf:group = dev6_app
pool.d/dev5.website.com.conf:group = dev5_app
pool.d/dev2.website.com.conf:group = dev2_app

Each site runs a laravel app, with the storage directory made group writable:

/var/www/dev3.website.com# ls -la
total 2236
drwxr-xr-x  20 root dev3_app    4096 Jul 17 21:39 .
drwxr-xr-x   9 root root        4096 Jul 17 21:33 ..
...
drwxrwxr-x   7 root dev3_app    4096 Jul 17 21:29 storage

nginx connects via TCP port:

server {
    listen         80;
    server_name    dev3.website.com;

    root /var/www/dev3.website.com/public;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        fastcgi_pass 127.0.0.1:9001;
        fastcgi_index index.php;

        # include the fastcgi_param setting
        include fastcgi_params;

        # SCRIPT_FILENAME parameter is used for PHP FPM determining
        #  the script name. If it is not set in fastcgi_params file,
        # i.e. /etc/nginx/fastcgi_params or in the parent contexts,
        # please comment off following line:
        fastcgi_param  SCRIPT_FILENAME   
        $document_root$fastcgi_script_name;
    }
}

With this configuration I get

The stream or file "/var/www/dev3.website.com/storage/logs/laravel-2019-07-17.log" could not be opened: failed to open stream: Permission denied

When I run chmod a+w on the storage directory it works.

I have also run ps -ef |grep php:

root      2468     1  0 00:53 ?        00:00:05 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
root     11897 10961  0 22:12 pts/0    00:00:00 grep --color=auto php 

已采纳解答

原帖链接 · Tim · CC BY-SA 4.0

I am suspecting that it is running the "master process" as the root user but for each of the pools it runs the "worker" processes as the specified user. This is further supported by the fact that you had to chmod the logs directory in order to get it to work.

A troubleshooting step you could take is to have one of the sites write a file to /tmp/test and then check to see what user owns it.

You could also write a loop that sleeps for a couple of minutes inside one of the pool and then run your ps -ef | grep php command to see if the "master process" has spawn a process as the user you expect.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-07-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。