How to Install PHP 7.2 on Ubuntu 18.04?

PHP 7.2 is included by default in Ubuntu’s repositories since version 18.04.

Update Ubuntu

Again, before doing anything, you should update your server:

sudo apt-get update && apt-get upgrade

Install PHP 7.2

Next, to install PHP 7.2 on Ubuntu 18.04, just run the following command:

sudo apt-get install php

This command will install PHP 7.2, as well as some other dependencies.

To verify if PHP is installed, run the following command:

php -v

You should get a response similar to this:

PHP 7.2.3-1ubuntu1 (cli) (built: Mar 14 2018 22:03:58) ( NTS )

And that’s it. PHP 7.2 is installed on your Ubuntu 18.04 server.

Install PHP 7.2 modules

These are the most common PHP 7.2 modules often used by php applications. You may need more or less, so check the requirements of the software you’re planning to use:

sudo apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php

To check all the PHP modules available in Ubuntu, run:

sudo apt-cache search --names-only ^php