O'Reilly logo

Mac OS X Hacks by Rael Dornfest, Kevin Hemenway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Turning on PHP

PHP is a fabulous scripting language for beginners to try their hands at serving up dynamic web content.

Much like server-side includes [Hack #94], PHP code is included and interpreted into the actual HTML of your web pages. Here, we’ll show you how to turn it on (it’s installed by default on OS X), as well as how to certify that it’s working properly.

As with the hacks on CGI and SSI, turning on PHP involves searching for the feature name (in this case, php) within the Apache configuration file [Hack #89]. The first entries we’ll run into are:

# LoadModule php4_module libexec/httpd/libphp4.so

...

# AddModule mod_php4.c

These two lines enable (or disable, if commented out with a #) the loading of PHP on Apache web-server startup. Since they’re commented out by default, we’ll have to uncomment them in order to have the modules loaded and PHP functional. Do so, and the lines should now look like this:

            LoadModule php4_module libexec/httpd/libphp4.so

...

AddModule mod_php4.c

Keep searching for php in the file and you’ll find:

# For example, the PHP 3.x module will typically use:
#
# AddType application/x-httpd-php3 .php3
# AddType application/x-httpd-php3-source .phps
#
# And for PHP 4.x, use:
#
# AddType application/x-httpd-php .php
# AddType application/x-httpd-php-source .phps

Tip

In some OS X installations (notably, 10.2 and higher), you won’t see the preceding lines. That’s alright; just add them in yourself.

In essence, these lines are saying that any file with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required