How to Install Nginx with PHP-FPM on Fedora 28/29/30

Nginx is an open-source, high-performance web server. It is known for its stability, very simple configuration, rich feature set, and low resource consumption.

The FastCGI Process Manager (FPM) is an alternative to the FastCGI configuration with multiple enhancements. This is useful for high load websites.

In This article,we will teach you how to installation and configuration of PHP-FPM with Nginx on your Fedora 28/29/30 Linux system.


Step 1. Installing Nginx and php-fpm

Install Nginx using the dnf command.

dnf install nginx php-fpm php-common

Step 2. Install PHP 7.2.12 modules

Select the modules you need to install.

dnf install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

Step 3. Configuring the firewall

if you server is protected by a Firewall, you need to open both HTTP (80) and HTTPS (443) ports.

Use the following commands to open the necessary ports:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Step 4. Configuring Nginx

We will create Nginx virtual host to run with FPM/FastCGI. For this tutorial, we use default VirtualHost. Edit VirtualHost host configuration file in a text editor. You can create new VirtualHost as per your requirements, so make sure to enable any new VirtualHost.

sudo vim /etc/nginx/sites-available/

Use the below basic Nginx Virtual host configuration with PHP FPM settings. Update the configuration as followings.

server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm;
        location / {
            try_files $uri $uri/ =404;
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;

Save your changes to the configuration file and create a link to site enabled directory.

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/ 

Step 4. Manage the Nginx Service

You can manage the Nginx service in the same way as any other systemd unit.

To start the Nginx service:

sudo systemctl start nginx

To stop the Nginx service:

sudo systemctl stop nginx

To restart the Nginx service:

sudo systemctl restart nginx

To check the status Nginx service:

sudo systemctl status nginx

To reload the Nginx service after you have made some configuration changes:

sudo systemctl reload nginx

To enable the Nginx service to start at boot:

sudo systemctl enable nginx

To disable the Nginx service to start at boot:

sudo systemctl disable nginx

Step 5. Verify Nginx and php-fpm Installation

Create a PHP script with phpinfo() function and place it to your server document root. Use below command to do it.

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

pen your web browser and visit the below URL:http://your-ip-address/info.php.You should see the phpinfo page.


All done. You have successfully configured Nginx web server with PHP-FPM on your Fedora 28/29/30 Linux System. Your server is ready to host websites.

Leave a Reply