Zhixian's Tech Blog


How to install PHP to Apache HTTP Server in Ubuntu 14.04 (Trusty Tahr)

Filed under: php, web application development — Tags: , , , , , , — Zhixian @ 10:36:12 am

This blog post describes how I install PHP to Apache HTTP Server and test the installation on my Ubuntu installation.


  1. Installation
  2. Verifying PHP5 Modules in Apache2 HTTP Folder
  3. Testing installation


The quick and simple way is to use Ubuntu Software Center (search term: php5).
This will install the latest version of PHP5 available in the Ubuntu Software Center.

Ubuntu Software Center_010

Verifying PHP5 Modules in Apache2 HTTP Folder

After the installation is complete, you should see Apache HTTP modules for PHP in the mods-enabled folder.
By default (if you installed Apache HTTP server via Ubuntu Software Center), the installation folder is located at:


In the installation folder, there should be a folder labeled mods-enabled.
In this folder, you should see a php5.conf (that holds your configuration settings for PHP5) and php5.load (the actual Apache2 module for PHP5) file.

zhixian@SARA: -etc-apache2-mods-enabled_011

Testing installation

After you confirmed that PHP module is enabled in PHP, you can test your installation.
To do so, create a test.php file in Apache’s document root folder.
By default, the document root folder is located in /var/www/html.
However, the owner and group access for this folder belongs to the root user.

html Properties_013

This means you need to access the /var/www/html folder as a superuser in order to make changes to the folder.
One way would be start a terminal session and enter the following commands:

gksudo caja /var/www/html &

zhixian@SARA: ~_015

If you are not using Mate desktop, replace “caja” with “nautilus” as in:

gksudo nautilus /var/www/html &

This command can be explained as follows:

gksudo – run command as superuser. This is similar to the sudo command. But because we are running the command in the background (see & below), the prompt to allow us to enter administrator’s credentials will be in the background as well. By using gksudo, we will get a prompt like the below, that allows us to enter administrator’s password.

Workspace 1_016

caja (or nautilus) – command to activate your file manager

/var/www/html – parameter used by file manager. File manager use this parameter and open this folder when it start.

& – The ampersand indicates that this command is to run in the background. If this is missing, the terminal session will be dedicated to run the file manager until the file manager application terminated.

After you run the command, you should see:

html (as superuser)_017

In this folder, create a file call test.php with the following contents:

<title>PHP Test Page</title>
<h2>A PHP test page</h2>
<?php echo “hello world”; ?>

test.php (-var-www-html) - gedit (as superuser)_018

Now, your /var/www/html folder should look something like this:

html (as superuser)_020

Go to your browser and navigate to:


You should see a result like the below:

PHP Test Page - Google Chrome_021

Blog at WordPress.com.