Explains all the steps required to install PHP 7 on Ubuntu 18.04 LTS. Also, install the apache extension to enable for the Apache HTTP Server.

How To Install PHP 7 On Ubuntu 18.04 LTS
How To Install PHP 7 On Ubuntu 18.04 LTS
April 17, 2019

This tutorial explains all the steps required to install the default distribution of PHP 7 on Ubuntu 18.04 LTS. The steps should be similar to other Linux based systems. In case you are planning to use PHP with the Apache HTTP Server, you can install Apache 2 before starting the installation of PHP 7. It can be done by following the guide - How To Install Apache 2 On Ubuntu 18.04 LTS published by Tutorials24x7.

Install PHP 7

In this step, we will install PHP 7.2, the default PHP package available for Ubuntu 18.04 LTS release. It can be installed using the command as shown below.

# Refresh indexes
sudo apt-get update

# Install PHP 7.2 on Ubuntu 18.04 LTS
sudo apt-get install php7.2

# Autoclean
sudo apt-get autoclean

# Autoremove
sudo apt-get autoremove
# OR
sudo apt-get --purge autoremove

It will ask to confirm the installation. Press Y and hit Enter to confirm the installation. The above-mentioned command will install the PHP at /usr/bin/php7.2 and place the configuration file at /etc/php/7.2/cli/php.ini.

Install Apache2 Module and MySQL Extension

Use the below-mentioned commands to install the Apache2 Module for PHP and MySQL extension.

# Install Apache2 Module if not installed by default
sudo apt-get install libapache2-mod-php7.2

# Install MySQL Extension
sudo apt-get install php7.2-mysql

Additional Extensions

You can also install the additional extensions in order to fully support a web application. Some of these packages might not be required in your scenario, hence it's totally optional to install these extensions.

# Install CGI and CLI if not installed by default
sudo apt-get install php7.2-cgi php7.2-cli

# Install CURL and JSON extensions
sudo apt-get install php7.2-curl php7.2-json

# Install PHP GD and Imagick
sudo apt-get install php7.2-gd php-imagick

# Multibyte String, Internationalization and Spell Check
sudo apt-get install php7.2-mbstring php7.2-intl php7.2-pspell

# Emails
sudo apt-get install php7.2-imap

# SQLite
sudo apt-get install php7.2-sqlite3

# Tidy and XML RPC
sudo apt-get install php7.2-tidy php7.2-xmlrpc

# Excel
sudo apt-get install php7.2-xsl

sudo apt-get install php7.2-fpm

Install OPcache to enable caching at the bytecode level.

# Install OPcache extension
>sudo apt-get install php7.2-opcache

Install the extensions to handle compressed files.

# Install Zip
>sudo apt-get install php7.2-zip

These are the steps required to install PHP 7 on Ubuntu 18.04 LTS and the additional packages that are mostly required for the website development.


This is how we can install PHP 7 on Ubuntu 18.04 LTS and also enable it's extension for the Apache HTTP Server. We have also installed the popular extensions for PHP which are required to host web applications.

Write a Comment

Click on the captcha image to get new code.
Discussion Forum by DISQUS