This article is the third in a mini-series of quick reference guides for installing Apache, PHP, and MySQL in Ubuntu 18. In this article we will cover the installation of PHP 7.2 and the Apache PHP module. Lastly we’ll verify PHP works with Apache.
My environment for these steps is Ubuntu 16 running on VirtualBox in Windows 10 x64.
Check out the previous articles where we installed Apache HTTP Server and MySQL.
Update Ubuntu package list
First, make sure your Ubuntu packages list is up to date.
sudo apt update
Let’s install PHP now, along with the Apache PHP module
Open a new terminal and type
sudo apt-get install php libapache2-mod-php
You will be notified that additional disk space will be used and prompted to continue. Hit
PHP and the Apache 2 PHP module will be downloaded and installed. This may take a few minutes depending on your internet connection.
When it has finished, you can verify the PHP version that was installed by using the
You should see something like this:
PHP 7.2.15-0ubuntu0.18.04.1 (cli) (built: Feb 8 2019 14:54:22) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.15-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
We can also check the installed PHP modules using the
This will return a list of all the installed modules. Some additional modules we’ll want to install are
curl. We’ll do that next.
Additional PHP modules can be installed at any time. Type the below command to install the
sudo apt-get -y install php-mysql php-curl
Restart Apache after the new modules are installed:
sudo systemctl restart apache2
You can also check the status of Apache
sudo systemctl status apache2
Verify PHP and Apache configuration
The standard way to verify a PHP / Apache installation is to use PHP’s inbuilt
phpinfo() function which outputs information about PHP’s configuration. Refer to the PHP Manual for more info.
Change into the Apache document root
Create a new file named
sudo touch info.php
info.phpin a text editor
sudo gedit info.php &
Paste the below PHP script. This will output details of the PHP installation and configuration:
<?php phpinfo(); ?>
Open your web browser and navigate to
This page should output PHP configuration details, including any installed modules. This confirms that PHP is correctly installed and the Apache PHP module is working.
Two important settings to note are the
Configuration File (php.ini) Pathand the
Loaded Configuration File. This is where the
php.inifile (PHP’s configuration file) is located:
If you also installed the PHP modules
mysqlyou can confirm that on this same page.
Hit Ctrl + f and search for curl and confirm it shows as enabled: