I want to share the most simple and straightforward configuration that suited my needs for developing locally.
First of all, make a quick backup of your current default
file in /etc/apache2/sites-available/
like this:
cd /etc/apache2/sites-available/
sudo mv default .default.bckp
Now create a new file called default
in the sites-available directory with the following content
<VirtualHost *:80>
ServerName test1.local #the local hostname
DocumentRoot /var/www/test1 #the corresponding document root
</VirtualHost>
<VirtualHost *:80>
ServerName test2.local
DocumentRoot /var/www/test2
</VirtualHost>
Now add the local hostnames to your /etc/hosts file and you’re good to go!
127.0.0.1 localhost test1.local test2.local
PS: I'm sure this conf is won't fit in a production ready environment, but for a local setup it's just amazingly simple and effortless.