Ubuntu: How to Enable or Disable an Apache2 Site / Virtual Host

Sites or virtual hosts are extremely useful when you are hosting more than one website on a box. I’ve already shown you how to set up virtual hosts under Apache 2, but I thought I would quickly just give a little more insight into what the a2ensite and converse a2dissite function calls do.

All that a2ensite is, is a script that enables specified sites (which contain a
block) within the apache2 configuration.

It achieves this by creating symlinks within /etc/apache2/sites-enabled. The opposite of doing this is a2dissite which disables the site by removing that symlink.

Funnily enough, you can enable or disable a site multiple times without getting an error, simply because all these scripts are doing is manipulating symlinks. Lastly, the default site is handled specially, with a resulting symlink called 000-default in order to be loaded first.

And now you know.

Related Posts:

  • To set up a virtual host (vhost) under Apache on your Ubuntu server is relatively simple. First you need to create a config file under the /etc/apache2/sites-available directory. A good practice is to name this file the same as the folder you want to use to hold this virtual host's web pages. For this example we ...

  • As a web developer I need to juggle a number of projects on my development machine all at once. The simple way to get around accessing these various sites is to set up a number of subdomains under localhost, one for each project. In other words: http://project1.localhost/ http://project2.localhost/ http://p ...

  • In the event that you've traditionally had your Apache webserver serving up SSL-encrypted web traffic on your Ubuntu server and you've now gone and changed your mind (or simply don't want to pay for the privilege of someone else saying you're perfectly safe and okay, here, have this certificate, now where's the mon ...

About Craig Lotter

South African software development manager and senior application developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.

One thought on “Ubuntu: How to Enable or Disable an Apache2 Site / Virtual Host

Leave a Reply