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


How to configure ServerName directive globally for Apache HTTP Server

After installing Apache HTTP Server, you may notice that that when you restart the service, you may get the following annoying message:

Could not reliably determine the server’s fully qualified domain name, using Set the ‘ServerName’ directive globally to suppress this message

zhixian@SARA: ~_017

To get rid of this message, you need to define a ServerName for your Apache HTTP Server.
To achieve this, you need to:

  1. Define a “fqdn.conf” file in Apache HTTP Server’s available configuration folder.
  2. Enable the “fqdn.conf” configuration
  3. Restart Apache HTTP Server

Implementation Details

1. Define “fqdn.conf”

Apache HTTP Server’s available configuration folder can be found at:


To create the “fqdn.conf” file, enter the following command into a terminal session:

echo “ServerName localhost” | sudo tee /etc/apache2/conf-available/fqdn.conf

zhixian@SARA: ~_018

What this command does is to write the string “ServerName localhost” into a file “fqdn.conf” at “/etc/apache2/conf-available/”.

2. Enable configuration

To enable the “fqdn.conf” that we just added to Apache HTTP Server, enter the following command in a terminal session:

sudo a2enconf fqdn.conf

zhixian@SARA: ~_019

3. Restart Apache HTTP Server

To restart the Apache HTTP service, enter the following command in a terminal session:

sudo service apache2 reload

zhixian@SARA: ~_020

After you restart the service, you should no longer see set “ServerName directive globally” message.



Blog at WordPress.com.