oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button Apache Web Serving With Mac OS X

Apache Web-Serving with Mac OS X, Part 6

by Kevin Hemenway

Editor's Note: Following the first five Apache Web-Serving with Mac OS X articles, Kevin Hemenway returns with a "put your legs up" sixth tutorial. This time he walks you through the various Apache modules that come with your Mac OS X installation and shows you what they can do.

It's quiet at GatesMcFarlaneCo. Yes, stereotypically too quiet. The clickety-clack, snickety-snack of typing continues uninterrupted, save for a gurgle here and there from the bubbler down the hall. Lewis and Carroll, normally jibber-jabbering like banshees on a hot summer day, are calm, cool, and unbelievably, collected. What is going on!?


Ever since you showed off Apache under Mac OS X a few short months ago, things have been simmering down -- no longer are emotions flaring or reboots frequent. Frantic service pack and security patches are but a memory. People no longer shake uncontrollably when they make changes to the Web server. Work has become a much more enjoyable watering hole. Soon, there will be no more cat-and-dog debates, and you'll be sharing slide shows of your vacations.

In these dull times, we've got plenty of freedom to fall deeper into the arms of Apache, tracing our fingers around the features we get free of charge. As our knowledge expands, we'll mine further into Apache's default modules, learning the tricks they provide and how to apply them to our desires.

There are a decent number of modules shipped with Apache, so thus begins a two-part article concerning them, as well as the mojo-jojo that can be yours. We'll keep these articles updated as time goes on, so they'll always be a handy reference, whether you're using Apache on OS X, Linux, or Windows.

Some Initial Notes About Modules

You can think of Apache modules as plugins:

  • Any programmer can create a module.
  • Modules add new features to Apache.
  • Modules can be enabled or disabled.

Related Reading

Apache: The Definitive Guide
Vital Information for Apache Programmers and Administrators
By Ben Laurie, Peter Laurie

Due to Apache's popularity, a large collection of user-created modules exists, all available for your downloading pleasure (some may not work or install correctly under Mac OS X, however). There are modules that enhance Apache's authentication, provide support for new languages, throttle bandwidth, check security, process ecommerce transactions, and much more.

Below, we'll focus on the modules that come with a default installation of Apache on Mac OS X (10.1.4 was used as the basis for this article). If you've been a fervent follower of this series, you know how to enable and disable modules -- you ran through those steps when you enabled PHP. I'll recap what you already know quickly:

  • If you examine your /etc/httpd/httpd.conf file, you'll notice two large blocks of module related text -- a large LoadModule block, and a similar AddModule block. Any module listed under the LoadModule block has a similar line under AddModule. The reverse holds true as well.
  • Modules are enabled by two directives: LoadModule and AddModule. If you comment or uncomment (by inserting or removing a # character) a LoadModule line, you've got to do the same for the matching AddModule line and vice versa.
  • The actual modules are installed under /usr/libexec/apache/ on your hard drive. Module files generally follow the naming scheme of mod, an underscore, and then their purpose or description, like mod_php and mod_mime_magic. There are exceptions to this rule, like libperl for mod_perl.

With those basic thoughts out of the way, let's revisit some familiar faces. As is usual, any fiddling you do with the Apache configuration file will involve stopping and starting the Web server before the changes take effect. As explained in Part 4, you can use most of the directives below in a properly configured .htaccess file, removing the need for an Apache restart.

Modules We've Already Used

As we've progressed through the previous five articles, we've actually been using multiple modules along our way to GatesMcFarlaneCo stardom. To stroll down memory lane, we'll say "hi" to some of our old friends and then move on to our other neighbors. I'll show you the matching LoadModule and AddModule lines, utter some compliments, and then point to the article that used its features.

The first few should be familiar as they're "major" features of Apache -- most of the "little" features we've played with are smaller parts of other modules, and as such, we'll expand our coverage whenever possible.

CGI Scripts

The following lines load this module:

    LoadModule cgi_module         libexec/httpd/
     AddModule mod_cgi.c

Comment on this articleLet's talk modules and what you're doing on Mac OS X.
Post your comments

CGI scripts are programs installed on the Web server that perform specific tasks -- such as mailing the results of a form, allowing someone to comment in a guest book, interactive message boards, and so on and so forth. mod_cgi grants us this capability and was covered in Apache Web-Serving with Mac OS X, Part 2. There's not much more this module offers besides what we've discussed previously -- just some logging directives that can be helpful in debugging broken scripts.

Server Side Includes

The following lines load this module:

    LoadModule includes_module    libexec/httpd/
     AddModule mod_include.c

The Server Side Include module allows us to dynamically insert other files or scripts into our Web pages before they're actually displayed to our visitor. They also allow conditional statements, can perform simple file tests, and more. In Part 2 of our series, we enabled SSI as well as demonstrated how to include the results of a CGI script. Clever use of SSIs can create mini-applications, like this image gallery.

PHP Processing

The following lines load this module:

    LoadModule php4_module        libexec/httpd/
     AddModule mod_php4.c

PHP is a full-fledged programming language that is very popular on Web servers, and often installed by default. It can do everything a CGI script could do, offers fast and easy connectivity to powerful databases, and is well supported by the Web-developer community. We enabled PHP in Part 3 and tested its database connectivity with MySQL in Part 5.

Pages: 1, 2, 3

Next Pagearrow