For create a virtual host in ubuntu please follow the below step by step process.

Virtual host name is : “local.dating”
Document root for that virtual host : “/var/www/dating”

1. Create a file with name of your virtual host(name you want for your virtual host like “local.dating”) on “/etc/apache2/sites-available/”.

2. Write the following code on that file :

/*******************************************************************/

#
# local.dating
#

ServerName local.dating
#ServerAlias www.sitename.com
DocumentRoot /var/www/dating
CustomLog /var/log/apache2/local.dating-access.log combined
ErrorLog /var/log/apache2/local.dating-error.log

/*******************************************************************/

3. Now you have to enable this virtual host. To do so please go to your terminal and type following command

sudo a2ensite local.dating

To disable a virtual host use following

sudo a2dissite local.dating

where local.dating is the name of the virtual host you want to enable/disable.

4. Now apache is almost ready to restart, but before doing so, we must inform our linux system that dev.example.com and www.dev.example.com are not to be looked for on the net, but on the local machine instead.
To do so, simply edit “/etc/hosts” and add the new host names at the end of the line beginning by 127.0.0.1, which is localhost like below :

127.0.0.1 local.dating

5. And now we are done, simply reload apache by following command :

sudo /etc/init.d/apache2 reload

Open your web browser and enter the following address local.dating. Magic, it runs the same as when you were using http://localhost/dating but it is far more usefull when devellopping a web service and want to be able to develop applications on your machine just like it is where the real web site.

Tagged with:  

2 Responses to How to create a virtual host in ubuntu?

  1. Cherise Blatter says:

    geiler Artikel…wo ist der Facebook button? :-)

  2. Stanton Bhat says:

    geiler Artikel…wo ist der Facebook button? :-)

Leave a Reply