Install PHP (7.1, 7.2, 7.3, 7.4) on Ubuntu, Debian

This guide will show you how to install different version of PHP on Ubuntu, and Debian. For the sake of this guide, we will demonstrate PHP 7.1 installation steps on an Ubuntu 16.04. However, these instructions can also be applied if you are running Ubuntu 17, 18, 19, or 20.04.

 Add PHP Repository

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

Install 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

Configur3 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

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.

No comments:

Comments with links will not be published.

Powered by Blogger.