Daniel 'MaTachi' Jonsson

How to Set Up a Virtual Host on Ubuntu

Add a new site:

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite.local

Then configure the site to fit your needs:

sudo vim /etc/apache2/sites-available/mysite.local

Don’t forget to add this line to the VirtualHost element:

ServerName mysite.local

Enable the site:

sudo a2ensite mysite.local

Reload Apache:

sudo service apache2 reload

Update your hosts file:

sudo vim /etc/hosts

Add the following line to the file:

127.0.0.1 mysite.local

Open a browser and visit mysite.local. Make sure that you don’t precede the URL with www..

If the browser doesn’t show what you are expecting, start with checking Apache’s error log:

cat /var/log/apache2/error.log | tail