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 ...

  • The extremely useful mod_rewrite or rewrite module is not enabled by default on a new Apache web server install. Luckily, this turns out to be pretty simple to rectify. Using the a2enmod function, simply run: sudo a2enmod rewrite sudo /etc/init.d/apache2 restart The first line will enable the rewrite modu ...

  • Unfortunately domain names are seldom cast in stone when it comes to commercial products, because as with most things, people tend to change their minds further down the line. If for the last three years your web application has been running under the domain myapp.com but now the boss has decided that it should ...

About Craig Lotter

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.

  • Developer89

    brilliant