Wern Ancheta

Adventures in Web Development.

Quick Tip: How to Setup Virtual Hosts in Ubuntu

| Comments

In this quick tip I’ll show you how you can setup virtual hosts for Apache in Ubuntu.

The first thing that you need to do is clone the default Apache configuration. In the example below myproject.dev is the virtual host name that you want to use.

1
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myproject.dev.conf

Open the new configuration file and update the values for the ServerName, ServerAlias, and DocumentRoot. Where ServerName is the virtual host name and the ServerAlias is the www version. The DocumentRoot is the absolute path to the directory where your project is stored.

1
2
3
4
5
6
7
<VirtualHost *:80>
        ServerName myproject.dev
        ServerAlias www.myproject.dev

        ServerAdmin wern@localhost
        DocumentRoot /home/wern/www/antares-backend
</VirtualHost>

Next, enable the new virtual host configuration.

1
sudo a2ensite myproject.dev

Lastly, add it to the hosts file.

1
sudo nano /etc/hosts
1
2
127.0.0.1       antaresapp.dev
127.0.0.1       www.antaresapp.dev

Comments