Install and Configure PHP 7.0 or PHP 7.1 on Ubuntu 16.04

Ubuntu

PHP and related packages are the most commonly used components when deploying a web server. In this article, we will learn how to setup PHP 7.0 or PHP 7.1 on Ubuntu 16.04 LTS.

Since Ubuntu 16.04, PHP 7.0 has replaced PHP 5.x and become the default version of PHP in the official Ubuntu application repository. You can install and configure PHP 7.0 on your Ubuntu 16.04 system as follows.

First of all, you can list all of the available PHP 7.0-related packages for review:

Then you can install the package your to-be-deployed application requires.

For example, if you want to deploy your application based on the LAMP stack, usually, you can install the below packages after installing Apache:

Alternatively, if you want to deploy your application based on the LEMP stack, you can install the following packages after installing Nginx:

After the installation, you can confirm that with:

The output should resemble:

The main config file of PHP 7.0 will be saved as /etc/php/7.0/apache2/php.ini (Apache) or /etc/php/7.0/fpm/php.ini (Nginx). You can use the vi text editor to modify relevant settings in that file.

or:

Remember to restart Apache or Nginx if you make any changes to that file or any other PHP config files:

or:

Install and configure PHP 7.1

If you want to install PHP 7.1, the latest stable release of PHP at the time of writing this article, on Ubuntu 16.04, a convenient method is to use the PPA (Personal Package Archives) repository.

First of all, you need to add specified PPA to the system apt repository:

Then you can list all of the available PHP 7.1-related packages for review:

From now on, you can install and configure PHP 7.1 in the same fashion as mentioned in the chapter about PHP 7.0 above. Basically, replacing 7.0 with 7.1 in relevant commands will get your job done.

That’s it. Thanks for reading.

Source

Share: