As a web developer I need to juggle a number of projects on my development machine all at once. The simple way to get around accessing these various sites is to set up a number of subdomains under localhost, one for each project. In other words:
- http://project1.localhost/
- http://project2.localhost/
- http://project3.localhost/ …
So how do we go about doing this then?
First, edit your /etc/hosts file by adding the following line:
127.0.0.1 project1.localhost
Next, create a new configuration file in /etc/apache2/sites-available/ using:
gksudo gedit /etc/apache2/sites-available/project1
In this configuration file, add the following:
<VirtualHost *:80>
DocumentRoot /home/username/project1
ServerName project1.localhost<Directory /home/username/project1/>
Options Indexes FollowSymLinks MultiViews +Includes
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Save the file, and then run the following:
sudo a2ensite project1
Finally restart the Apache Server.
sudo /etc/init.d/apache2 restart
And there you go. You should now be able to hit http://project1.localhost from your browser. Nice! :)
(Ubuntu 10.10 Maverick Meerkat)