How to Configure Nginx for PHP-FPM on Fedora 40 or 39

When you install PHP-FPM on Linux distributions like Debian or Ubuntu, you commonly use the “www-data” user. However, you don’t do this for RHEL or Fedora Linux installations. By default, the PHP-FPM service runs under the “apache” user, which doesn’t work with “nginx”. Therefore, you must adjust the configuration for correct usage.

This guide will give you a quick overview of changing this using terminal commands.

Open www.conf Configuration File

First, open the configuration file (www.conf) with the following command:

sudo nano /etc/php-fpm.d/www.conf

Open the configuration file and replace the (Apache) user and group with the (Nginx) user and group as the images demonstrate below:

As above, locate “user” and “group” that have “apache”, which you now change to “nginx” as demonstrated below:

Press (CTRL+O) to save, then press (CTRL+X) to exit.

Make the necessary adjustments, then restart your PHP-FPM service.

sudo systemctl restart php-fpm

Example Nginx PHP-FPM Server Block Code

To handle PHP files with Nginx, you must configure the server block, as shown in the example below. Use this example for all server{} blocks that manage PHP files, and ensure you include “location ~ .php$.” in the configuration.

Example ONLY:

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

To verify that the changes made to the previous code did not cause any errors, you can use the following command to test the Nginx configuration.

sudo nginx -t

Example output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

To complete the PHP-FPM setup, restart the Nginx service.

sudo systemctl restart nginx


In conclusion, adjusting the PHP-FPM service user from “apache” to a more compatible user like “nginx” on RHEL or Fedora is crucial for seamless integration with your server setup. By following the terminal commands outlined in this guide, you can ensure that your PHP-FPM service runs smoothly with “nginx”, avoiding potential permission issues and enhancing the overall performance of your web applications. This simple configuration change helps maintain a consistent and efficient environment across different Linux distributions.

Joshua James
Follow me
Latest posts by Joshua James (see all)