Setup Apache virtual host on Ubuntu

This post is mostly a self reminder. I have updated my system to Ubuntu 14.04 and that leads to set up almost everything once again. I observed that I forgot few key steps about setting this up. So it’s better to note it down so that next time I don’t have to find again.

1. Create conf
$ sudo vim /etc/apache2/sites-available/myapp.conf

<VirtualHost *:80>
    ServerName project1

    DocumentRoot /var/www/project1/web
    <Directory /var/www/project1/web>
        Order allow,deny
        Allow from all
        Satisfy Any
        AllowOverride All
        Options -Indexes
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerName project2

    DocumentRoot /var/www/project2/web
    <Directory /var/www/project2/web>
        Order allow,deny
        Allow from all
        Satisfy Any
        AllowOverride All
        Options -Indexes
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerName localhost

    DocumentRoot /var/www
    <Directory /var/www>
        Order allow,deny
        Allow from all
        Satisfy Any
        AllowOverride All
        Options -Indexes
        Require all granted
    </Directory>

2. Enable the virtual host
$ sudo a2ensite myapp.conf

Now the symlink should be seen
$ ls -lt /etc/apache2/sites-enabled/
total 0
lrwxrwxrwx 1 root root 29 Jun 30 20:55 myapp.conf -> ../sites-available/myapp.conf

3. Restart Apache
sudo service apache2 restart

It should echo OK
* Restarting web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[ OK ]

4. Edit hosts
$ sudo vim /etc/hosts

Add

127.0.0.1 project1
127.0.0.1 project2

That’s all.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s