Earthtracker's Blog

Just another WordPress.com weblog

Setup virtual host in ubuntu

Setup virtual host in ubuntu is pretty simple.

Hope you have already apache2 installed.

Now go to the location: /etc/apache2/sites-enabled
Open the file named ‘000-default’ as root.

You will find some line for default localhost .

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
       DocumentRoot /var/www
	<Directory />
		Options FollowSymLinks
		AllowOverride All
	</Directory>
......

Add the following line

ServerName localhost

Now copy the full section between

<VirtualHost *:80></VirtualHost>

under this part .
Change the code like below.

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName mydomain.com

	DocumentRoot /var/www/project-folder-name/
	<Directory />
		Options FollowSymLinks
		AllowOverride All
	</Directory>
	<Directory /var/www/project-folder-name/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>

.......... 
</VirtualHost>

Others will remain same.

Save the file.

Now fine the host file from /etc/hosts
Add the following line

127.0.0.1	mydomain.com

Save the file.

Now restart your apache.
sudo /etc/init.d/apache2 restart

Enjoy browsing your new virtual host. 🙂

Leave a comment »