The usual configuration in the Apache Web Server stems from a single point - httpd.conf
, the main configuration file. There might be other configuration files but they are mostly referred to from this central config file with the Include
directive. For example, you might find lines like,
Include conf.d/
in the core configuration file. It is also not uncommon to find that these included configuration files have another Include
directive in them which includes other files/directories.
The point to keep in mind is to not overuse this flexibility feature the Apache Web Server offers, since you end up only complicating things for yourself and more often than not, for the person after you.
Today, we'll be looking at enabling/disabling modules and sites in the Apache Web Server.
To enable modules, use,
$ sudo a2enmod <name-of-module>
## E.g.:
$ sudo a2enmod headers
When a module is enabled, a symlink to the respective module in the mods-available
directory is created in the mods-enabled
directory.
To disable a module, use,
$ sudo a2dismod <name-of-module>
## E.g.:
$ sudo a2dismod headers
When a module is disabled, the symlink created for the respective module in the mods-enabled
directory is removed.
Note: A server restart is mandatory after enabling/disabling a module. -
$ sudo service apache2 restart
Usually, when you have multiple sites running on the same server, you use VirtualHosts
. It's nicer to have each sites' VirtualHosts configuration in their own separate files rather than put them all together.
Make sure you have the site-specific / VirtualHosts configuration file loaded and ready-to-go in a file, before we start playing with the next part.
A VirtualHosts configuration file, looks a little like this:
Do NOT use this VirtualHost configuration as yours, it is very much insecure and meant to be this way only for my local development web server!
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory "/var/www">
Require all granted
AllowOverride all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined
</VirtualHost>
To enable sites, use,
$ sudo a2ensite <name-of-config-file>
## E.g.,
$ sudo a2ensite site1.conf
Similar to what happens with modules, when a site is enabled, a symlink to the config file at sites-available
is created at sites-enabled
To disable sites, use,
$ sudo a2dissite <name-of-config-file>
## E.g.,
$ sudo a2dissite site1.conf
And just as with the modules, the symlink in sites-enabled
is removed when a site is disabled.
Note: A server configuration reload is mandatory after enabling/disabling a module -
$ sudo service apache2 reload
Download the official 2buntu app for both Android and Ubuntu Touch.