# /etc/apache2/apache2.conf - pulls in additional # configurations in this order: Include /etc/apache2/mods-enabled/*.load Include /etc/apache2/mods-enabled/*.conf Include /etc/apache2/httpd.conf Include /etc/apache2/ports.conf Include /etc/apache2/conf.d/[^.#]* Include /etc/apache2/sites-enabled/[^.#]* </span
Debian stores its Apache 2.0 configuration files in the directory <kbd>/etc/apache2</kbd>. Normally the main Apache configuration file is called <kbd>httpd.conf</kbd>. Although that file exists on Debian, it is only there for compatibility with other software that expects it to exist. The real configuration starts with the file <kbd>apache2.conf</kbd>. You can still add configuration statements to <kbd>httpd.conf</kbd>, as <kbd>apache2.conf</kbd> includes it, but you would do well to ignore that fact. Your hand-edited changes should go elsewhere (see below).
Debian adds another configuration file, <kbd>ports.conf</kbd>, which contains the <kbd>Listen</kbd> directives telling the Apache server what IP address and port to listen to (Apache 2 no longer uses the <kbd>Port</kbd> directive.) I'm not sure why the maintainers decided to break this out into a separate file.
The best place to put your own custom configurations is in the <kbd>conf.d</kbd> directory. Files in this directory are included as part of the "global" server configuration and will apply to all virtual hosts (see below). For example, if all the sites on your server use the Yahoo User Interface libraries, you might store one copy of the libraries in a central location that can be shared across all sites, and create a file <kbd>/etc/apache2/conf.d/yui.conf</kbd> with an <kbd>Alias</kbd> directive to map it to the same URL space for all sites.
# Files related to Apache modules /etc/apache2/mods-enabled/*.load /etc/apache2/mods-enabled/*.conf /etc/apache2/mods-available/*.load /etc/apache2/mods-available/*.conf /usr/sbin/a2enmod /usr/sbin/a2dismod </span
One of the great advantages of the Apache web server is its modular architecture. You can add or remove functionality as dictated by your requirements. In the default Apache build, you would find a section near the top of your <kbd>httpd.conf</kbd> file with instructions to load each module. Later in the file, you would find configuration sections specific to each module, possibly wrapped in a <kbd><IfModule></kbd> directive. This arrangement can be tricky from the perspective of a system administrator who may need to install or uninstall various Apache modules. Identifying the configuration changes that are required by a module or that require a specific module can be difficult to do by hand and even harder to automate with a script.
To make things easier on the server administrator, Debian takes advantage of the fact that Apache configuration files may contain an <kbd>Include</kbd> directive which pulls in additional configuration files. Debian creates two non-standard directories: <kbd>/etc/apache2/mods-enabled</kbd> and <kbd>/etc/apache2/mods-available</kbd>. Whenever you install an Apache module from a Debian package, the module will drop one or two files into the <kbd>mods-available</kbd> directory. The mandatory <kbd><var>module</var>.load</kbd> contains the Apache <kbd>Load</kbd> directive to load the module into your web server. The optional <kbd><var>module</var>.conf</kbd> file contains additional configuration directives necessary for the operation of the module.
Installing a module from a Debian package makes it available to your server, but does not automatically activate the module in your server. To activate the module, use the <kbd>a2enmod</kbd> command:
a2enmod <var>module</var> /etc/init.d/apache2 force-reload
The <kbd>a2enmod</kbd> command will create symbolic links in the <kbd>mods-enabled</kbd> directory pointing to your <kbd><var>module</var>.load</kbd> and, if it exists, <kbd><var>module</var>.conf</kbd>. To force a running Apache to re-read its configuration files and thus load the module, you must then send it the <kbd>force-reload</kbd> signal.
Likewise, to disable a module:
a2dismod <var>module</var> /etc/init.d/apache2 force-reload
You can, of course, manage the symbolic links in the <kbd>mods-enabled</kbd> directory directly, but it is usually safer to use the provided scripts. Issue either command without a <var>module</var> argument and it will print for you a list of appropriate module names.
# Files related to Apache virtual hosts /etc/apache2/sites-enabled/[^.#]* /etc/apache2/sites-available/* /usr/sbin/a2ensite /usr/sbin/a2dissite </span
A <dfn>Virtual Host</dfn> is just a web site served by your Apache server. Virtual hosts are managed just like modules. Each site gets its own configuration file that contains all the Apache directives that pertain only to that site. These files (or symbolic links to them) should be placed in the <kbd>sites-available</kbd> directory. There are no strict naming requirements for these files (files beginning with "." or "#" will be ignored), but for convenience you should name each site configuration file to match the domain name it is serving. There is no need to add a "conf" extension. For example, <kbd>control-escape.com</kbd> is the file used for this web site.
To activate any of these sites, use the <kbd>a2ensite</kbd> command, which operates identically to the <kbd>a2enmod</kbd> command mentioned above. There is a respective <kbd>a2dissite</kbd> command for disabling a site.
Even if you only run one web site on your server, Apache is still configured to have one virtual host, the <dfn>Default Virtual Host</dfn>. The default virtual host is treated specially by the <kbd>a2ensite</kbd> script. If you look in your <kbd>sites-enabled</kbd> directory you will find that the link has been named <kbd>000-default</kbd>. The number is prepended to the name by the <kbd>a2ensite</kbd> script to ensure that the default virtual host is the first one included by Apache (which sorts the files alphabetically). If you want other sites to be loaded in a particular order other than alphabetical, you can rename the links here, but you should always ensure that the default virtual host is the first one loaded.
Although Debian's configuration setup for Apache 2 is non-standard, it is still fairly easy to understand, and it provides tools that make life easier for the administrators of web servers that change often or serve multiple web sites. For additional help, view the Debian README file at <kbd>/etc/apache2/README</kbd>. For general information on configuring Apache, try these resources.
To learn more about Debian GNU/Linux, visit Debian.org.
To learn more about Ubuntu, visit Ubuntu.com, or buy a copy of The Official Ubuntu Book
This article originally appeared at www.control-escape.com/web/configuring-apache2-debian.html and is published here under a Creative Commons Attribution-Share Alike License.
Netdip.com is an excellent web site that's powered by TYPO3 and other great open source software. Netdip.com is also a fat free alternative to ice cream.
Add comment