Short guide to set up an apache virtual host on ubuntu 14.04

Knowing, that there are very good and detailed guides for virtual host creation, i decided to have a shortest possible how to on this topic here.
Assuming, that you have installed and running your apache in Ubuntu 14.04 Trusty Tahr, then these are the steps to create a new virtual host:

  • assure, that the directory, where your virtual host should to “live” in, exists (e.g. “/var/www/awesome.local”)
  • assure, that the permissions of your document root are set to 755
  • create an apache virtual host configuration file (copy the default config file)
    • sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/awesome.local
    • fill it with your configuration (with the editor of your choice)
  • <VirtualHost *:80>
        ServerAdmin admin@awesome.local
        ServerName awesome.local
        ServerAlias www.awesome.local
        DocumentRoot /var/www/awesome.local
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
  • enable the virtual host configuration:
    sudo a2ensite awesome.local
  • restart apache:
    sudo service apache2 restart
  • set up your local /etc/hosts:
    • open the file “etc/hosts”
    • add the line awesome.local www.awesome.local
  • open http://awesome.local and/or http://www.awesome.local in your browser and check, if everything went well (if you see an empty page, check, that there is something in your document root ;))

Leave a Reply

Your email address will not be published. Required fields are marked *