This article is the third in a mini-series of quick reference guides for installing Apache, PHP, and MySQL in Ubuntu 16. In this article we will cover the installation of PHP 7 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 article where we installed Apache HTTP Server.
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
When it has finished you can verify the PHP version that was installed by using the
You should see something like this:
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, 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
Make sure to restart Apache after a new module is added:
sudo /etc/init.d/apache2 restart
You can also check the status of Apache
sudo /etc/init.d/apache2 status
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 and 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.
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: