Post below shows us how to create a user friendly URL as or for our applications rather than seeing http://localhost/folder/another-folder/test in browser. Assuming that our web document folder is var/www/html on Ubuntu.

Current status

Currently we have "index.php" file in project folder "test".

inanzzz@inanzzz:~$ ls -l /var/www/html/test
total 4
-rw-rw-r-- 1 inanzzz inanzzz 21 Mar 28 08:22 index.php

Update hosts file

Add line below to "hosts" file, save and exit.

inanzzz@inanzzz:~$ sudo nano /etc/hosts
[sudo] password for inanzzz: localhost

Create a config file

We're going to replicate existing "000-default.conf" but will update its content later on.

inanzzz@inanzzz:~$ ls -l /etc/apache2/sites-available
total 12
-rw-r--r-- 1 root root 1332 Jan 7 2014 000-default.conf
-rw-r--r-- 1 root root 6437 Jan 7 2014 default-ssl.conf
inanzzz@inanzzz:~$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.conf
inanzzz@inanzzz:~$ ls -l /etc/apache2/sites-available
total 16
-rw-r--r-- 1 root root 1332 Jan 7 2014 000-default.conf
-rw-r--r-- 1 root root 6437 Jan 7 2014 default-ssl.conf
-rw-r--r-- 1 root root 1332 Mar 28 08:34 test.conf

Update config file

Update "test.conf" so that its content reads like below.

inanzzz@inanzzz:~$ sudo nano /etc/apache2/sites-available/test.conf

<VirtualHost *:80>

DocumentRoot /var/www/html/local/test

<Directory />
Options FollowSymLinks
AllowOverride None

<Directory /var/www/html/local/test>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Enable the site/config

Command below adds symbolic link to "/etc/apache2/sites-enabled/" as "test.conf". To revert this process, use a2dissite in command.

inanzzz@inanzzz:~$ sudo a2ensite test.conf
[sudo] password for inanzzz:
Enabling site test.
To activate the new configuration, you need to run:
service apache2 reload

inanzzz@inanzzz:~$ ls -l /etc/apache2/sites-enabled/
total 0
lrwxrwxrwx 1 root root 35 Jan 13 22:56 000-default.conf -> ../sites-available/000-default.conf
lrwxrwxrwx 1 root root 33 Mar 28 08:57 test.conf -> ../sites-available/test.conf

Restart Apache

To activate what we have done so far, Apache needs to be restarted.

inanzzz@inanzzz:~$ sudo service apache2 restart
* Restarting web server apache2 [ OK ]


If you call or, your application should be accessible now.