php-fpm이 풀에 지정된 사용자로 실행되지 않습니다.

php-fpm이 풀에 지정된 사용자로 실행되지 않습니다.

nginx와 php-fpm(7.2)이 설치된 Ubuntu18.04 웹 서버가 있습니다.

6개의 풀이 있으며 각각 고유한 사용자와 그룹이 있습니다.

/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

각 사이트는 그룹 쓰기 가능으로 설정된 스토리지 디렉터리를 사용하여 laravel 앱을 실행합니다.

/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는 TCP 포트를 통해 연결합니다.

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;
    }
}

이 구성을 사용하면

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

저장소 디렉토리에서 chmod a+w를 실행하면 작동합니다.

또한 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 

답변1

루트 사용자로 "마스터 프로세스"를 실행하고 있지만 각 풀에 대해 지정된 사용자로 "작업자" 프로세스를 실행하는 것으로 의심됩니다. 이는 로그 디렉터리가 작동하도록 하기 위해 chmod를 수행해야 한다는 사실로 인해 더욱 뒷받침됩니다.

취할 수 있는 문제 해결 단계는 사이트 중 하나에 파일을 쓴 /tmp/test다음 해당 파일을 소유한 사용자가 누구인지 확인하는 것입니다.

풀 중 하나에서 몇 분 동안 대기하는 루프를 작성한 다음 명령을 실행하여 ps -ef | grep php"마스터 프로세스"가 예상한 사용자로 프로세스를 생성했는지 확인할 수도 있습니다.

관련 정보