/dev/trouble
Eric Roller's Development Blog

Running Apache locally for debugging

- Posted in General by

Let's first take a look at how Apache is configured (for Mac OS X 10.5.6 Leopard). In the Terminal:

> httpd -V
Server version: Apache/2.2.9 (Unix)
Server built:   Sep 19 2008 10:58:54
Server's Module Magic Number: 20051115:15
Server loaded:  APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture:   32-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/private/var/run/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

Notice where the configuration file is (see last line); this is the file we would use if we enabled the web server from the System Preferences : Sharing : Web Sharing. However, we much rather not change that configuration file; instead we shall simply supply a different one that we keep outside the /private/etc area.

[more]

Before we go ahead with our personal configuration file, it is a good idea to compare our settings to those provided by Apple; use a "diff" tool of your choice (I like twdiff that comes with BareBones' TextWrangler). Once our settings are complete, we shall begin with a syntax check:

> apachectl -f /path/to/conf/httpd-debug.conf -t
Syntax OK

To launch Apache with our own configuration, we run:

> sudo apachectl -f /path/to/conf/httpd-debug.conf -k start

To verify that it is running, we can issue this command (when o.k. we will get multiple lines for multiple httpd instances):

> ps -e | grep httpd | grep usr

Finally, to view the web site in Safari, we simply open the location: http://localhost/ .