To specify a custom PHP-FPM user and group in Nginx, you need to make changes to the Nginx configuration file. Here are the steps to follow:
Open your Nginx configuration file. By default, it is located at /etc/nginx/nginx.conf
or /etc/nginx/sites-available/default
.
Find the location ~ \.php$
block in your Nginx configuration file. This block handles PHP files.
Add the fastcgi_param
directives to set the PHP_VALUE
for the desired user and group. Add the following lines to the location ~ \.php$
block:
fastcgi_param PHP_VALUE "user=<username>";
fastcgi_param PHP_VALUE "group=<groupname>";
Replace <username>
and <groupname>
with your desired PHP-FPM user and group.
Save the configuration file and exit the editor.
Restart Nginx to apply the changes:
sudo systemctl restart nginx
With these changes, Nginx will pass the specified PHP-FPM user and group through the PHP_VALUE
environment variable to PHP-FPM. PHP-FPM will then execute the PHP scripts with the specified user and group.