How To Install PHP 7.4 on Ubuntu Server

Current Stable Release of PHP is 7.4.1 released on 18 December 2019. In this article, we learn how to install the latest PHP 7.4 on Ubuntu Server. PHP 7.4.1 is available for production environments and you can install it via the Ondrej PPA repository.

PHP is one of the most used programming languages on the internet. Make sure you get the latest version installed for security and bug fixes. You can check here, what are the latest security vulnerabilities in PHP.

PHP is a very popular Server Side Scripting Language best known for interactive web pages and dynamic websites. We will learn the installation of PHP 7.4 in some simple steps. Just follow the below steps for installing PHP 7.4 on Ubuntu Server.

Step 1: Add Ondrej PHP PPA Repository

All the Ubuntu supported PHP build packages are present in ppa:ondrej/php PPA repository. You can add it by using the below command.

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

Step 2: Install the latest PHP version on Ubuntu Server

The Ondrej PPA repository is having all the supported PHP packages for ubuntu. So that you can install any version of PHP using this repository.

You can also see the available versions of PHP by using the below command.

sudo apt list | grep php

But in the article, we install the latest PHP 7.4 by using the below command.

sudo apt-get -y install php7.4

After this, You get the latest PHP 7.4 installed in Ubuntu Server. To see the version of installed PHP, use the below command.

php -v

You will see the output as below

[email protected]:~# php -v
 PHP 7.4.1 (cli) (built: Dec 18 2019 14:44:04) ( NTS )
 Copyright (c) The PHP Group
 Zend Engine v3.4.0, Copyright (c) Zend Technologies
     with Zend OPcache v7.4.1, Copyright (c), by Zend Technologies

After that, you can install the additional packages of PHP by using the below command.

sudo apt-get install php7.4-xxx

Replace xxx with the package name. For example if you want to install the PHP JSON package then you should run the following command.

sudo apt-get -y install php7.4-json

Or you can install multiple packages with single command like below.

sudo apt-get install -y php7.4-{mysql,mbstring,json,gd,bz2,bcmath}

All the PHP related configuration of apache server will exist in /etc/php/7.4/apache2/php.ini

Installing the PHP 7.4 with Nginx

The default installation of PHP is configured for the Apache Web Server. If you want to install the PHP 7.4 with Nginx, you have to stop and disable the service of Apache Web Server. You can do it by below command.

sudo systemctl disable --now apache2

Now we install PHP-FPM with Nginx. By running below command.

sudo apt-get -y install php7.4-fpm nginx

Now start and enable the PHP-FPM and Nginx services By running below command.

systemctl start php7.4-fpm
systemctl start nginx
systemctl enable php7.4-fpm
systemctl enable nginx

You can verify that both services are running by using the below command.

systemctl status php7.4-fpm
systemctl status nginx

All the PHP related configuration is present in /etc/php/7.4/fpm/pool.d/www.conf

That’s it, you have the latest stable PHP 7.4 install and running now.


In the article, we learned how to install PHP 7.4 in Ubuntu Server. If you face any problem in following this article then you can mention it in the comment section.

Also Read: How To Install OpenLiteSpeed Web Server on Ubuntu 16.04 LTS

You may also like...

Leave a Reply

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