Apache VirtualHost on Ubuntu

Here’s a quickie tutorial on how to add Virtual Hosts to Apache on Ubuntu. This tutorial assumes that you have a basic understanding of Apache configuration and that your Apache is installed and able to serve websites.

  1. cd /etc/apache2/sites-available
  2. sudo vim yourdomain.com.conf and enter your VirtualHost directive. Below I’ve put the most basic example, see Apache docs for details and additional features:
    <VirtualHost *>
      ServerName yourdomain.com
      DocumentRoot /home/youruser/public_html
    </VirtualHost>

    Save & exit.
  3. sudo vim /etc/hosts and add your new domain to the 127.0.0.1 localhost line so it looks like this:
    127.0.0.1 localhost yourdomain.com
    Save & exit.
  4. Enable your new virtualhost:
    sudo a2ensite yourdomain.com.conf
  5. Reload the Apache configuration:
    sudo /etc/init.d/apache2 reload

That’s it! Repeat for each of your VirtualHosts.

—————-
Now playing: Al̬may̬hu Esh̬t̩ РTchero Adari N̬gn
via FoxyTunes

5 Responses to “Apache VirtualHost on Ubuntu”

  1. Michal Gorski says:

    Great and easy tutorial! Thanks a lot. But for virtual host to work, I needed to add “” instead of “”.

  2. Michal Gorski says:

    Ups – something went wrong in previous post. OK, again – I replaced * with *:80 to make it work.

  3. Danilo says:

    Good tutorial!
    Simple and direct!!

    Trank’s

  4. […] Apache VirtualHost on Ubuntu | Tequila Fish (tags: ubuntu dns virtualhost) […]

  5. abhijeet says:

    nice & simple tutorial