For those who seek help in different areas of software and hardware platform.

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

This guide will show you how to install the different version of PHP on Ubuntu and Debian. For the sake of this tutorial, we are using Ubuntu 16.04 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:

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:
Then, restart the PHP-FPM service:
sudo systemctl restart php7.1-fpm

Wrapping up

You can install any version of PHP such as 7.2, 7.3 or 7.4 on Ubuntu or Debian using the same installation steps.


Post a Comment

Comments with links will not be published.

Video Tutorials