Localhost is a hosting place in your own computer. There are a vast number of Localhost servers you can use. The most used and popular of them is Apache. Localhost enables you to test your work on your computer itself, instead of testing on a live server on the web. If you are creating a project, Localhost is the best place to test that project. In this tutorial I will show you how to create a localhost site running on Apache Server in any Linux Distribution.

This tutorial is for Ubuntu versions 10.10 and below. The latest versions from 11.04 should see this tutorial.

Apache Server Installation

We need to install Apache server first. To install Apache Web Server open Terminal and do the following command :

sudo apt-get install apache2

The Apache Server will be downloaded and installed automatically. After installation continue to the next part of this tutorial.

Site Creation

Open the Terminal CTRL + ALT + T. Make a copy of /etc/apache2/sites-available/default, let’s make the copy name mysite. (Name depends on the site you wish to create). The following command wil copy the file and name the new file as mysite.
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite

Now edit the new file to configure :

sudo gedit /etc/apache2/sites-available/mysite
Then, Add the following contents in the file using gedit we just opened. Please read the 3 conditions below and then paste the content.
  1. You will need to change the codes ‘username’ shown below to your home folder name.
  2. You will need to change the names ‘mysite’ shown below to your desired site name.
  3. You can also change the web address of your site by renaming “mysite.com” to the site address you want.

Content that should be added to the file :

<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName mysite.com
  DocumentRoot /home/username/mysite
  <Directory /home/username/mysite/>
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   Order allow,deny
   allow from all
  ErrorLog /var/log/apache2/mysite/error.log
  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn
  CustomLog /var/log/apache2/mysite/access.log combined

Once you’ve saved these changes, you’ll need to enable the site. ( You will need to change the name ‘mysite’ shown below to the name of the file you create at “/etc/apache2/sites-available/” ).

cd /etc/apache2/sites-available && sudo a2ensite mysite

We specified a separate directory for storing log files, so we’ll need to create that log directory.( You have to change the name ‘mysite’ shown below to the name you given in the configuration file on “/etc/apache2/sites-available/” ).

sudo mkdir /var/log/apache2/mysite

Finally, we need to point the site address to localhost in your hosts file. For that, Edit /etc/hosts :

sudo gedit /etc/hosts

and add the following at the end of the file. ( You need to change the web address “mysite.com” shown below to your address given on the file in sites-available folder ). mysite.com

Now we restart Apache Server using Terminal to apply all the changes we made.

sudo /etc/init.d/apache2 restart

You can now store all your work in /home/you home name/site name and navigate to it by pointing your browser to the address you gave.