Enable PHP on Apache without modifying the default httpd.conf file

DIY / Tech April 2nd, 2008

I’ve recently been setting up a local Apache server on Mac 10.4.11 to do some simple development in PHP and came across this method for setting it up nicely.

With this method, you can create your own custom file which will override the default Mac Apache server settings without modifying the original
httpd.conf file. Why not just change the httpd.conf file itself?
Well, Apache updates may overwrite this file with a new default and I
find consolidating custom changes in one small file is easier to edit
and troubleshoot. You may need admin editing permissions to do this.

How to:

1. PHP is not enabled by default, so you need to switch this on.
These are located in: /private/etc/httpd/httpd.conf

2. Create a new file called whatever you wish in the directory:
/private/etc/httpd/users/myhttpd.conf

In this example I used ‘myhttpd.conf’ for my custom settings. The default httpd.conf file will load any files within the ‘users’ directory.

3. Look for and copy the following code from httpd.conf into your new file:
#LoadModule php4_module libexec/httpd/libphp4.so

and
#AddModule mod_php4.c

and
<IfModule mod_php4.c>
# If php is turned on, we repsect .php and .phps files.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

# Since most users will want index.php to work we
# also automatically enable index.php
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>

That last bit is odd that you’d need to copy it, but apparently it runs in sequential order, so it’s necessary to minimally grab the ‘AddType’ definitions (you don’t need the whole conditional, but it’s included for reference)

4. Remove the # (comment) characters from the first 2 so they look like:
LoadModule php4_module libexec/httpd/libphp4.so
and
AddModule mod_php4.c

5. Save your file and you should be good to go!

One Response to “Enable PHP on Apache without modifying the default httpd.conf file”

  1. Semiconducted » Blog Archive » Enable php 5 on Apache 2 for Mac OS X Leopard 10.5.3 by Damon Hamm Says:

    [...] Notice: Mac OSX 10.5.3 Leopard uses Apache 2 and has different file paths from Mac 10.4.11 Tiger (Apache 1). The older instructions for Apache 2 / Mac OS X 10.4.11 are located here: http://www.semiconducted.com/diy-tech/2008/enable-php-on-apache-without-modifying-the-default-httpdconf-fil... [...]

Leave a Reply