DWQA QuestionsInstall php 7.2 on ubuntu 16.04 ?
kundan roy asked 4 years ago


PHP 7.2 is the latest stable version of PHP and has many new features, improvements, and bug fixes. You should definitely use it if you want a better, faster website/application.

Update Ubuntu
Of course, as always, first update Ubuntu:

apt-get update && apt-get upgrade
Add the PHP repository
You can use a third-party repository to install the latest version of PHP. We’ll use the repository by Ondřej Surý.

First, make sure you have the following package installed so you can add repositories:

apt-get install python-software-properties
Next, add the PHP repository from Ondřej:
add-apt-repository ppa:ondrej/php
And finally, update your package list:
apt-get update
Install PHP 7.2
After you’ve added the repository, you can install PHP 7.2 with the following command:
apt-get install php7.2

To check if PHP 7.2 is installed on your server, run the following command:
php -v
Install PHP 7.2 modules
You may need additional packages and modules depending on your applications. The most commonly used modules can be installed with the following command:
sudo apt-get install php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml
And that’s all. You can now start using PHP on your Ubuntu server.

If you want to further tweak and configure your PHP, read our instructions below.
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. So the instructions are pretty similar to PHP 7 for 16.04.
Update Ubuntu
Again, before doing anything, you should update your server:

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:
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