There are several ways of doing this. Making subdomains are maybe the most widespread. But I found this much easier – and intuitive :)

First, I added a couple of new hosts in /etc/hosts

127.0.0.1 localhost
127.0.0.2 alpha
127.0.0.3 beta
127.0.0.4 gamma

In /var/www, I added the folders alpha, beta, gamma containing index.php

<?php echo getcwd(); ?>

Then I added a new site in /etc/apache2/sites-availabe/

sudo nano greek
# alpha
<VirtualHost 127.0.0.2>
	DocumentRoot /var/www/alpha/
</VirtualHost>
# beta
<VirtualHost 127.0.0.3>
	DocumentRoot /var/www/beta/
</VirtualHost>
# gamma
<VirtualHost 127.0.0.4>
	DocumentRoot /var/www/gamma/
</VirtualHost>

And finished of with:

sudo a2ensite greek
sudo /etc/init.d/apache2 reload

firefox alpha now showed /var/www/alpha

This was first published here.

About these ads