How To Install PHP-FPM on Ubuntu Server 20.04

Louis SanchezJuly 29th 2021, 7:30

Follow these steps to install PHP_FPM

Step 1 : Add PHP PPA Repository

sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Step 2 : Update the apt package repository and install PHP_FPM

sudo apt update
sudo apt install php7.4 php7.4-fpm

Step 3 : Run command to install additional packages:

sudo apt install php7.4-{mysql,curl,json,cgi,xsl,gd,common,xml,zip,soap,bcmath}

Step 4 : Check if FPM services is properly installed and running

sudo service php7.4-fpm status

Step 5 : Configure Nginx to use the PHP processor. We will modify the /etc/nginx/sites-available/ file:

sudo nano /etc/nginx/sites-available/

Step 6 : Find a line stating the priority of the index file and add index.php as a first option:

index index.php index.html index.htm index.nginx-debian.html;

Step 7 : Next, add the following two location directives

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

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

Step 8 : Save the changes and exit the file. Restart PHP_FPM and Nginx for the changes to take effect:

sudo service php7.4-fpm restart
sudo service nginx restart

Step 9 : Create an index.php file with some PHP code in it at the path mentioned in the default site configuration

sudo nano /var/www/
<?php phpinfo(); ?>

Step 10 : Open your browser and point it to your domain. You should see the result of your PHP script: