Thursday, October 25, 2012

Creating virtual host in ubuntu

Suppose, the configuration file name is domain.com and local IP address is 127.0.0.1. Type following command in terminal
gksudo gedit /etc/apache2/sites-available/domain.com

Add following lines in configuration file
<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/test
    ServerName domain.com
    ServerAlias test.domain.com
    ServerAdmin admin@domain.com
</VirtualHost>

Save and close it. Then 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/domain.com .

Then, 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 test.domain.com
Save and close it. After all restart the apache service.

No comments:

Post a Comment