« Second Post | Main | Logging in Apache for IIS Admins »

01/21/2008

Production use for the Include Directive

At work we've finally gotten to the point architecturally where we are no longer implementing a brand new web site (with new server infrastructure) for every application so now it is time to start investigating ways to better manage httpd.conf. When you are part of a group of three or more administrators, each new application that comes along could have it's own Apache settings, mod_proxy settings, jkmounts, rewrites, etc., and they could be scattered all over the place within the httpd.conf. Managing the configuration becomes fairly difficult, especially if each new release contains minor changes to the main configuration file.

Simply create a new .conf file for the application and then use the apache Include directive to refer to the additional configuration file.

This idea is new to me--but it is not a new idea. I saw it after recently compiling a copy of apache on my own machine. It involves setting up separate configuration files per site, application, virtual server and just including them within the main apache configuration file.

Let's say you want to add php5 support into your apache server instance. Create a new configuration file that contains the following base configuration directives:

 LoadModule php5_module modules/libphp5.so
# This section adds filetype support for php files
<IfModule mod_php5.c>
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
</IfModule>

# This enables index.php as a default directory document
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule> 
Then, in your httpd.conf file, add the following at the bottom:
# Add PHP5 support into httpd.conf
Include httpd-php5.conf

It's pretty useful when you get 5 or 6 (or more!) different applications that might have their own mod_rewrite statements, aliases, jk mounts, mod_proxy balancer statements or virtual hosts. apachectl -configtest will still run through each configuration file in order to check the syntax of all directives and you will wind up saving time hunting for application-specific configuration data--assuming, of course, that you used descriptive names for these additional files.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a01156fbc6fe6970c011572287fed970b

Listed below are links to weblogs that reference Production use for the Include Directive:

Comments