Explains all the steps required to install PHP 7 on Ubuntu 18.04 LTS.

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. We also prefer to install Apache 2 before starting the installation of PHP 7. You can follow 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

# FPM
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.

Write a Comment

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