LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

How to install PHP 7.4 with Nginx and Apache on Ubuntu

This article was contributed by Dustin Cisneros at RackNerd, a web hosting and infrastructure as a service provider which was recently voted #1 by the LowEndTalk community! If you are looking for a Linux VPS, Ryzen VPS, Windows VPS, or shared and reseller hosting services, be sure to take a look at RackNerd’s latest special offers here.

PHP is a scripting language that is specifically suitable for web development. A lot of websites you visit today are based out of PHP. PHP offers multiple programming options and one of the most highlighting features of PHP is that it is quite simple to use, even for new programmers. There are more than one PHP version available currently, so you might want to consider the version that is supported by your application. The following article will guide you on how to install PHP 7.4 version with Apache and Nginx.

How to install PHP 7.4 with Nginx

PHP-FPM (“fastCGI process manager) shall be used here for managing the PHP files. This is required because Nginx cannot support processing PHP files, as we will see later for Apache. For installation of PHP and PHP-FPM, run the command below:

sudo apt update
sudo apt install php-fpm

The FPM service will start running as soon as the installation is done. To check its status use:

systemctl status php7.4-fpm

And then you will receive an output such as the below:

php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-06-09 19:07:05 UTC; 37s ago

The lines below can then be added for enabling Nginx to process the PHP files:

server {

 # . . . other code

   location ~ \.php$ {

     include snippets/fastcgi-php.conf;

     fastcgi_pass unix:/run/php/php7.4-fpm.sock;



For the new settings to produce full effect, restarting the Nginx service is necessary:

sudo systemctl restart nginx

How to install PHP 7.4 with Apache

For the installation of PHP  along with Apache module, the following command can be used:

sudo apt update
sudo apt install php libapache2-mod-php

Now restart the Apache for the effects to take place completely:

sudo systemctl restart apache2

How to install PHP extensions

PHP extensions are useful since they can expand the range of the PHP function. apt can be used to install the PHP extensions:

sudo apt install php-[extname]

In order to install the 2 extensions MySQL and GD , run the command below:

sudo apt install php-mysql php-gd

Once you have installed the new extensions then restart your system to let the changes take place completely, or restart your web server service.

Test PHP Processing

In order to find out if the configuration has been  done appropriately for PHP processing or not, you need to create the new file info.php within the /var/www/html  directory using the code below:


Once this step is concluded and the file has been saved, go to  http://your_server_ip/info.php to see whether the configuration has been done properly or not.

What to if your application doesn’t support PHP 7.4

In such a scenario, you can download the previous PHP versions as follows:

A repository containing various PHP versions can be run as follows:

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

Now attach the version number to the package name to install any version you want

sudo apt install php[version]

Here let us take an example as to how you can get the 7.1 version of PHP:

sudo apt install php7.1 php7.1-common php7.1-opcache php7.1-mcrypt php7.1-cli php7.1-gd php7.1-curl php7.1-mysql

We hope you enjoyed this tutorial on how to install PHP on Nginx or Apache on a Ubuntu based system. If you have any questions or feedback, feel free to leave them in the comments section below!



1 Comment

  1. Kin-iro Mosaic:

    Please don’t follow this, install 8.0 minimum.

    July 14, 2021 @ 6:11 am | Reply

Leave a Reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

Your email address will not be published. Required fields are marked *