How to install PHP 7.2 on Ubuntu 18.04

Install PHP on Ubuntu 18.04

PHP is one of the most popular programming language currently in the world. PHP has different versions 5.6, 7.0, 7.1 and 7.2. Currently, PHP 7.2 is the latest version of PHP which supports different frameworks like WordPress, Laravel, Code-Igniter etc. Ubuntu 18.04 ships with default PHP 7.2 support, We can easily install PHP 7.2 on Ubuntu 18.4. Ubuntu 18.04 is the current latest version of Ubuntu. This tutorial outlines how to install PHP 7.2 on Ubuntu 18.04.


Before you start installing PHP 7.2 on Ubuntu 18.04. You must have a non-root user account on your server with sudo privileges

1. Install PHP With Nginx

Nginx does not support native PHP processing. You will need to Install “fastCGI process manager” which is known as php-fpm

Run the following command to install php-fpm on your server. The following command will install php-fpm7.2

sudo apt install php-fpm

You can check the status where it is correctly installed or not by following command

systemctl status php7.2-fpm

You can check PHP version by running following command

php -v

2. Installing PHP With Apache

If you have Apache running at backend then we need to install PHP and Apache PHP module on the server. To install PHP 7.2 and Apache module type following command and press enter.

sudo apt install php libapache2-mod-php

After installing PHP and apache-php module you will need to restart Apache server by typing following command

sudo systemctl restart apache2

3. Install PHP Extensions

You will need to install some basic PHP extensions to run WordPress , Laravel like frameworks on the server. To install any of the PHP extensions on the server following is the basic format.

sudo apt install php-[name_of_the_extension]

You can install curl extension for PHP by running following command

sudo apt install php-curl

Following are some basic PHP extensions needs to be installed on your server

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

To install more extensions you can use the above format.

4. Testing PHP processing

To test whether PHP is configured on your server properly or not you should create a file test.php inside directory var/www/html/ with following code.



If you see the following output then you have installed PHP successfully.


In this tutorial, you have learned how to install PHP 7.2 on Ubuntu 18.04 successfully with some of its basic extensions useful for frameworks and tested successfully. If you have any of the queries regarding this then you can comment below.

Related Tutorials

  1. How to install Nginx on Ubuntu 18.04
  2. How to Secure Nginx with Let’s Encrypt SSL on Ubuntu 18.04