Tags

, ,

As a web developer you may work with several projects. Today I’m gonna show you how to setup virtual host in ubuntu linux managing your projects. This will help you to define a host-name for each project like local.smronju.com instead of localhost/smronju. So let’s make a virtual host with me.

Open a text editor and write those lines in it. Make sure to change /projects/smronju to your own file path, ServerAdmin and ServerName.

<VirtualHost *:80>
ServerAdmin webmaster@smronju.com
ServerName local.smronju.com
DocumentRoot /var/www/projects/smronju
<Directory /var/www/projects/smronju>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/smronju.error.log
LogLevel warn
CustomLog /var/log/apache2/smronju.access.log combined
</VirtualHost>

Then save the file to /etc/apache2/sites-available. Give it a name e.g: smronju
Add the following line in hosts file. Which is located in /etc/hosts

127.0.1.1 local.smronju.com      //change local.smronju to your own.

Open terminal and type the following command or copy and paste it.

sudo a2ensite smronju          //change smronju to your file name.

Now you have restart your apache server the following command.

sudo /etc/init.d/apache2 restart or service apache2 restart

Okay you are done. Open your favorite web browser and type local.smronju.com (in my case). If everything goes well you must see what you expect by default it will show you the following message.

It works!

Note: You can create virtualhosts as many as you want following the same method.

Advertisements