Software > Mac OS X Packages > PHP

PHP Apache Module

Introduction

This is a PHP module for the Apache web server included in Mac OS X.
PHP is a server-side, cross-platform, HTML embedded scripting language.

This particular build of the module is based on the most recent version 5.2.4 of the software. It runs on Mac OS X version 10.4/Tiger and is built as Universal Binary for compatibility with both Intel and PPC Macs.

Note: you should always check the PHP section of the user forum too, new releases of this software are usually announced and discussed there long before they are available on this page as stable builds.

The module includes support for lots of extensions, among them the ones listed below:

The distribution comes in a Mac OS X Installer package and is completely self-contained, there are no external dependencies beyond what is delivered by Apple in a regular Mac OS X installation. It does require that you have applied all available Software Updates for the current OS release.

Starting with PHP 5.1.4 the distribution is more modular and the extensions come as separate packages included in one big metapackage. The installer allows you to deselect the ones you don't want if you open the Customize dialog.

All software is installed into a new directory /usr/local/php5 on your boot volume. If you ever want to get rid of the package, you only have to remove this directory, symbolic links called +entropy-php.conf in either /etc/httpd/sites or /etc/httpd/users and, for older packages, a few easily recognized lines in the /etc/httpd/httpd.conf Apache web server configuration file.

NOTE: This module will only work with the original Apache web server as shipped by Apple.
If you re-built Apache from source, you will most likely see an error message like module structure is garbled when you try to restart the server after installing this module. You will have to build your own PHP module which matches your particular Apache. The build instructions might help you do this.

You might also be interested in an alternate PHP Distribution for Mac OS X called MAMP which does not interact with Apple's Apache webserver, includes MySQL and which might work on older releases of Mac OS X. I am not affiliated with MAMP in any way, but have heard good things about it. It seems to be well-suited for personal non-production development setups.

Installation Instructions

NOTE: If you have previously enabled Apple’s PHP module included in Mac OS X by un-commenting the respective lines in the httpd.conf file, you need to undo that change before you install this package, otherwise bad things will happen...

You have several download choices for the PHP module, but note I only support the current version of OS X and PHP. I have no time or interest to support older OS releases or PHP versions.

If you decide to use this PHP package for production use, you need to be aware of this policy, because future versions might force you to upgrade your OS or the PHP version.

If you bought and want to use a license key for the commercial version PDFLib from the folks at www.pdflib.com, make sure to enter the Customize screen in the installer, deselect the regular pdflib extension and select the pdflib_commercial one. Remember to do this every time you install/upgrade the package.

If you’re still on 10.3, an older, unsupported, probably insecure PHP 5.1.2 package for Apache 1.3 is available from this forum post. But I really recommend an OS upgrade instead.

PHP 5 on Mac OS X 10.4, PPC and Intel
 PHP 5.2.4 for Apache 1.3
 PHP 5.2.4 for Apache 2
  1. Download the appropriate installation package from the list above.
  2. Unpack the compressed .tar.gz file but DO NOT USE StuffIt Expander, use Apple’s BOMArchiveHelper or the command line.
  3. Double-click the installer package and follow the directions of the installer application.

PHP should now be up and running. You can test it by dropping a file named test.php into your Sites folder in your home directory. Into that file, write this line:
<?php phpinfo() ?>.

Now open up http://127.0.0.1/~your_username/test.php in your web browser.
You should see a status table with information about the PHP module.

The download storage and bandwidth for this website are provided by my hosting ISP Hostpoint. I am very happy with their service as they have been handling the massive amount of traffic flawlessly for years for a very good price. If you need a reliable hosting partner, please have a look at their offerings.

Update Instructions

If you previously installed an older version of the module, you should be able to upgrade by simply installing the newer version over the old one.

The new version should be active afterwards, you can test with the phpinfo() tip given above.

Examples

FAQ

This section list a few frequently asked questions and their answers. Some of them are rather old and might not be appropriate for current OS X and PHP package releases so if in doubt you should check the forum for the most up-to-date information.

Can I install both the PHP 4 and 5 packages on the same system?

(Since I’m no longer maintaining PHP4 packages, this is for old packages only). Yes, but you can’t run both at the same time. I have configured the PHP 5 package to install into /usr/local/php5 and the PHP 4 package into /usr/local/php. You should be able to switch by changing the Include line in the Apache config file /etc/httpd/httpd.conf accordingly. See this forum post for details.

Where is the php.ini file?

At /usr/local/php5/lib/php.ini (/usr/local/php/ for PHP version 4). I have included the “recommended” file as delivered by the PHP group.

Most people asking for this seem to be interested in setting up e-mail for PHP. This little tool might be helpful in getting OS X's built-in postfix mail server running: PostFix Enabler

My PHP code is not executed.

The package installs with short_open_tags disabled. This means that you need to open your PHP code blocks with <?php and not just <?.

If you use the short form, you should go through all your PHP files and change it.

How do I use it from the command line?

You have to use the full path /usr/local/php5/bin/php and not just php. That will invoke Apple's original PHP module.

Will this run on Mac OS X Server?

It should. You might need to add the MIME type mappings for the .php file extensions manually. Check the user forums, especially the nice explanations here.

How can I get this to work together with the mod_dav WebDAV module? (a.k.a. error message Undefined symbols: _XML_ErrorString)

You need to change the order of the LoadModule and AddModule directives in the Apache configuration file /etc/httpd/httpd.conf so that the WebDAV module is loaded and added after the PHP module. Big thanks to Chris Janton for this tip.

BTW, There are very useful instructions for getting WebDAV and iCal etc. to work on OS X at Greg Westin's site

Why do I get stuff like {\rtf1\mac\ansicpg10000\cocoartf100 on every page?

You probably used TextEdit to edit your .php file. Don't edit your text files with TextEdit! It will insert lots of RTF formatting code into your HTML and PHP code, which is what you're seeing.

Do yourself a big favor and get BBEdit or TextWrangler! This is one of the best programs ever written for the Macintosh (some people say it's a reason to buy a mac), and if you regularly edit text files containing code like HTML or PHP, you definitely need this!

Can I also get the CGI version of PHP?

Yes. It is included in the package in /usr/local/php5/bin, along with many other goodies.

Additional Information

Build Instructions

I have automated the entire build process using a bunch of Perl classes and some helper files which I have published. It should be possible to reproduce this build, but I cannot offer any support for this because I just don't have the time for it. Either rebuilding from source packages with this stuff works for you as-is, or it doesn't.

The relevant material is available in the Subversion Repository/

Acknowledgements

Big thanks to

5. September 2007