Tech News

How To Install PHP 7.1, 7.2, 7.3, 7.4 on Ubuntu 16/17/18/19


This guide will show you how to install the different version of PHP on Ubuntu 16, 17, 18 and 19. For the sake of this tutorial, we are using Ubuntu 16 and PHP 7.1 as an example.

Enabling PPA

If you are on Ubuntu 16, the only version of PHP available in its default repository is 7.0 and therefor you need to add Ondrej’s PPA to get the PHP version of your choice:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Installing PHP 7.1

Once you enabled the ondrej/php PPA, you can install PHP 7.1 using the below command:
sudo apt-get install php7.1
To install PHP7.1 including some of the most commonly used modules you can use the following command:
sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm

Configuring PHP

Once the installation is completed you need to edit the php.ini file:

Find the php.ini configuration file like below:
sudo php --ini |grep Loaded
You will see the output similar to the following:

Output
Loaded Configuration File: /etc/php/7.1/cli/php.ini

Edit the file using your preferred text editor:
sudo nano /etc/php/7.1/cli/php.ini
Make the following changes:
cgi.fix_pathinfo=0
Then, restart the PHP-FPM service:
sudo systemctl restart php7.1-fpm

Wrapping up

In this guide, we installed PHP 7.1 on Ubuntu 16 to give you an example. You can install PHP 7.2, 7.3 or 7.4 using the same method.

No comments

Comments with links will not be published.