How to install and configure PHP 7.2 on Ubuntu 18.04

PHP and all related packages are very important and most commonly used components when deploying a web server. This article will describe how to configure PHP version 7.2 for an operating system such as Ubuntu, version 18.04.

Ubuntu update

First you need to update the list of available Ubuntu packages

sudo apt-get update -y

Next, you need to install updates

sudo apt-get upgrade -y

Create your user sudo

You can add a user by executing the following command:

adduser <username>

Further, after the user is successfully added, it will be proposed to install the necessary information about this user

Enter the new value, or press ENTER for the default
Full Name []: Test User
Room Number []: 01
Work Phone []: 5555555
Home Phone []: 5555555
Other []:

After successfully adding all the information and data, you need to add a new user to the sudo group

usermod -aG sudo <username>

To verify this, run the following command

ls -la /root

Web server setup

You can install either Apache, either Nginx.

To install Apache, use the following command:

sudo apt-get install apache2 -y
sudo systemctl start apache2.service

For Nginx, use the following command:

sudo apt-get install nginx -y
sudo systemctl start nginx.service

Install PHP 7.2

PHP 7.2 is included in the default Ubuntu repository for 18.04. You can list each of the available PHP 7.2 packages with the following command:

apt-cache pkgnames | grep php7.2

Next, to install the packages necessary for your application, enter the command:

sudo apt-get install php -y
sudo apt-get install php-{bcmath,bz2,intl,gd,mbstring,mysql,zip,fpm} -y

After that, restart your web server. This will allow PHP to get to work. For Apache, use the following command:

systemctl restart apache2.service

For Nginx, use the following command:

systemctl restart nginx.service

Confirm the PHP version:

php -v

If the correct steps have been taken before, then the conclusion should be as follows:

PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

The main PHP 7.2 configuration file will be saved as /etc/php/7.2/fpm/php.ini. You can use the vi text editor to change the corresponding settings in this file:

sudo vi /etc/php/7.2/fpm/php.ini

If you are making any updates to this file, then you will definitely need to restart your web server (Apache or Nginx).

Was this article helpful?

Related Articles

Leave A Comment?