Creating virtual host in ubuntu in some easy steps

After a long time, I get back to my blog. For last few days I was too busy for some LAMP projects. Hopefully now on, I will be available in my blog with new spicy topics.

Configuring a virtual host is really important if anybody works as web developer. It will give your separate hosting environment by keeping specific features from another one. Beside this, I have a plan to write a complete tutorial on setting up LAMP environment with proper extension for being a professional developer. Though it’s not so difficult, but sometimes it turns you in some troubles. However, let me explain it by following some easy steps . . .

Assuming that apache2 is already installed in your PC. if it is not, please follow this tutorial: https://help.ubuntu.com/6.06/ubuntu/serverguide/C/httpd.html. Whatever, first thing is to create configuration file in /etc/apache2/sites-available by gedit, nano or any other text editor. Suppose, the configuration file name is eftakhairulweb.com and local IP address is 127.0.0.1. Type following command in terminal….

gksudo gedit /etc/apache2/sites-available/eftakhairulweb.com

Add following lines in configuration file

<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/eftakhairulweb.com
    ServerName eftakhairulweb.com
    ServerAlias www.eftakhairulweb.com
    ServerAdmin [email protected]
</VirtualHost>

Save and close it. Now create a symbolic link of this configuration file to /etc/apache2/sites-enabled directory in order to enable it

cd /etc/apache2/sites-enabled/
sudo ln -s ../sites-available/eftakhairulweb.com .

Now, add a virtual domain with a specific local IP to hosts file that is located in /etc/hosts. You can also add the port using a colon with the IP.

sudo nano /etc/hosts

add this line

127.0.0.1.:80 eftakhairulweb.com

Save and close it. Almost done. Finally, restart the apache service.

sudo /etc/init.d/apache2 restart

Done. Keep it in your mind that you can make multiple name based virtual hosts based on your IP address. Best practice is make separate configuration for each virtual host.

 

Eftakhairul Islam

Hi, I'm Eftakhairul Islam, a passionate Software Engineer, Hacker and Open Source Enthusiast. I enjoy writing about technical things, work in a couple of startup as a technical advisor and in my spare time, I contribute a lot of open source projects.

 

8 thoughts on “Creating virtual host in ubuntu in some easy steps

  1. Nice post. Instead of the following two lines:

    cd /etc/apache2/sites-enabled/
    $ sudo ln -s ../sites-available/eftakhairulweb.com

    it can be done more easily using this:

    sudo a2ensite eftakhairulweb.com

    Cheers!

Leave a Reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Read previous post:
Set environmental variable PATH in Ubuntu

While I was installing Android SDK in my ubuntu. It was needed to set environment path. So I did a...

Close