Simple commands to manage apache2 sites and Modules
This tutorial will explain some useful commands to manage apache2 sites and Modules
Apache2 Configuration Files Location
First we will explain what is there under /etc/apache2/ directory
sites-available -- A list of configuration files -- one per site. A blank install will contain the file default. The system admin can have as many sites here as they need -- however -- they will not all be active.
sites-enabled -- A list of symlinks to configuration files in sites-available. A blank install will contain a symlink 000default to sites-available/default. The sites listed here are the sites which will be active. The site to be used if no virtual hosts match will be the first file found (hence the 000 on 000default).
mods-available -- A list of configuration files -- one or more per module. Each dpkg installed module will add files here. e.g. php4.conf and php4.load are added with the libapache2-mod-php package. Again -- the system admin can install whatever modules they wish -- however -- until they are set available they will not be active.
mods-enabled -- A list of symlinks to configuratioon files in modes-available. Only modules linked in here will be activated on the webserver.
Commands to use
a2ensite -- a2ensite is a script that enables the specified site (which contains a <VirtualHost> block) within the apache2 configuration. It does this by
creating symlinks within /etc/apache2/sites-enabled.
sudo a2ensite test
Note:- Test is the file you have created under /etc/apache2/sites-enabled/ with the required configuration
a2dissite -- a2dissite is a script that disables the specified site (which contains a <VirtualHost> block) within the apache2 configuration. It does this by removing symlinks within /etc/apache2/sites-enabled.
sudo a2dissite test
a2enmod -- a2enmod is a script that enables the specified module within the apache2 configuration. It does this by creating symlinks within /etc/apache2/mods-enabled.
sudo a2enmod imagemap
Enables the mod_imagemap module
a2dismod -- a2dismod is a script that disables the specified module within the apache2 configuration. It does this by removing symlinks within /etc/apache2/mods-enabled.
sudo a2dismod mime_magic
Disables the mod_mime_magic module.
You can check the list of available modules under /etc/apache2/mods-available
I believe the text under the first example should read sites-available instead of sites-enabled.
“Note:- test is name of the file you have created under /etc/apache2/sites-available/ with the required configuration”
I would like to mention apache2ctl. If i use a2dissite to disable a certain site it says.
Site virtdomain disabled.
Run ‘/etc/init.d/apache2 reload’ to activate new configuration!
A better way to restart to apache2 daemon to make changes take effect is
because (man apache2ctl):
This differs from a normal restart in that currently open connections are not aborted.
my 2 cents
to extend my comment above. The advantage over the /etc/init.d/apache2 reload method is when you host more then one domain in your setup the other virtual domains and their actual connections will not be affected/reseted by the restart.