root directory

Understanding Root Directory, Testing PHP Engine and Installing PHP Extensions on Ubuntu

In my previous post, Installing LAMP Stack on Ubuntu and Debian in Just 3 Steps, you’ve learned how to install LAMP Stack on Ubuntu.

In this post we’ll:

  1. learn what is Root Directory
  2. check whether PHP5 Engine is working correctly or not.
  3. learn about and install some useful PHP5 Extension Modules such as mcrypt.

1. What is Root Directory

The directory pointed by localhost is the root directory. This is the directory where we put our website and then tells browser to show the required file by typing in the address bar.

In Ubuntu the root directory is /var/www/html/. Whenever we’ll type localhost (which is equal to localhost/index.html or localhost/index.php, that’s why we don’t type index.html or index.php) in the browser’s address bar, as we did in the previous post, the server will look for the index.html or index.php in the root directory (/var/www/html/) and will present index.html as shown as below:


If you want, you can create other directories, subdirectories and so on and files in the root directory, but in this case you’ll have to mention the directory name and file name after the localhost such as localhost/directory/subdirectory/file.php. For example: if you put a directory named ‘mysite’ in the root directory then you’ll have to type localhost/mysite/index.php (you may also type only localhost/mystie) in the address bar of the browser.

2. Testing PHP5 Engine’s Working

Now, you know what the root directory is, we’ll create a phpinfo.php file in our root directory. Follow the steps given below:

  1. Open termianal
  2. Create and edit a file having name phpinfo.php
sudo gedit /var/www/html/phpinfo.php

the above command will create a file in /var/www/ html/and open it in gedit (if you don’t have gedit installed, replace the word gedit with nano). Type the following code in the phpinfo.php file:


Save the file and in the address bar of your browser type http://localhost/phpinfo.php hit enter and you should see the following page in your browser:


If you are seeing the page like in the above picture then it means PHP5 Engine and Apache Server both are working.

3. PHP Extension Modules

PHP Extension Modules are the extensions for PHP to enhance the performance of the language. You can easily add or remove these extension modules according to your needs.

Installing PHP Extension Module

Run the following command in your terminal to a PHP Module Extension.

sudo apt-get install php5-extension_name

Your may see the extensions name by the method given below. Look for your desired extension name and replace in the above command with extension_name. For example to install mysql extension run the following command:

sudo apt-get install php5-mysql

Watching the List of Available PHP Extension Modules

Run the following command in your terminal to see the available PHP Extension Modules.

apt-cache search php5-

Watching the Specification and Dependency of a PHP Extension Module

Run the following command in your terminal to see the the specifications and the dependency, that particular extension to others extension, PHP Module Extensions.

apt-cache show extension_name

Some Useful PHP Extension Modules

  • php5-mysql: A module to deal with MySQL database.
  • php5-exactimage: A C++ library for fast image processing by consuming less memory.
  • php5-facedetect: Used to detect faces with implementation of OpenCV library.
  • php5-imagick: Used to create and modify images using ImageMagick library.
  • php5-mcrypt: It provides a module for MCrypt function in PHP Script.
  • php5-memcache: Used to cache your web pages and/or their data.
  • php5-zmq: Used to design ans implement fast message-based apps.
  • php5-xdebug: Used to assist in debugging.


In this post we learn:

  1. what is a root directory.
  2. how to check that we’ve successfully installed PHP.
  3. what are PHP Extension Modules and how they can be installed to enhance the performance of PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *