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 for the Apache 2 web server provided by Apple in Mac OS X Leopard. It is built as Universal Binary for compatibility with both Intel and PPC systems.

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

The module includes many popular PHP extensions, among them:

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.

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 and a symbolic link called +entropy-php.conf in either /etc/apache2/sites or /etc/apache2/other, depending on whether you run OS X Client or Server.

Installation Instructions

Deactivate Other PHP Modules

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... The installer should catch this and refuse to install.

On OS X Server, you have to disable Apple’s PHP module in the Server Admin application, but the trick is that it only lets you do this if you have chosen the “Advanced” configuration style. In the “Standard” configuration, Server Admin will not let you disable the original Apple PHP. It might look like it does, but it will re-enable it behind your back.

About OS Versions

Note that I only support the current version of both OS X and PHP because I have no time or interest to support older OS releases or PHP versions. This means that you should only use these packages for production systems if you are prepared to update those systems to new Mac OS X versions fairly quickly. Once a new version of OS X is out, I usually have to adapt my build system with major, non-backwards compatible changes. After that’s done, I can’t build and release any more packages for the previous OS version.

Installation

With all of that out of the way, here’s the download link:

Entropy PHP 5.3.0-3.pkg

An older PHP 5.2 package:

Entropy PHP 5.2.9-7.pkg

Here’s an older, unsupported and probably insecure version for 10.4:

PHP 5.2.4 for Apache 1.3

To install the package:

  1. Download the appropriate installation package from the list above.
  2. 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 package, 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.

Where is the php.ini file?

At /usr/local/php5/lib/php.ini . 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

Why do I get an error message containing _xmlTextReaderSchemaValidate when I run apachectl configtest?

That is an unfortunate side effect of how Apple set up apachectl on Mac OS X and I don’t see a way to fix it. The message is harmless, the module will still load.

You can use the alternate command httpd -t which is what apachectl configtest does behind the scenes.

If you’re interested in the details, the problem is that apachectl sources /usr/sbin/envvars, which in turn sets the DYLD_LIBRARY_PATH variable to force a particular dynamic load order that gives preference to the system-supplied libxml instead of the one I ship as part of my package.

My PHP code is not executed and its source code is visible in the browser instead. Why?

The package installs PHP with the configuration option 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. The latter invokes Apple’s original and probably older PHP.

Will this run on Mac OS X Server?

Yes but you have to disable Apple’s PHP in the Server Admin application before installing this package.

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

You probably used TextEdit to edit your .php file. Don’t do that as it inserts 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!

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.

How do I uninstall the package?

You should be able to remove it completely by removing the directory /usr/local/php5 and the symbolic link named php5.conf in either /etc/apache2/other or /etc/apache2/sites (OS X Server).

Additional Information

Alternatives

There are other PHP distributions for Mac OS X users:

Build Instructions

I have automated the build process using a bunch of Perl classes and some helper files. 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 code for this build system is on github.

Acknowledgements

A big thank you to

21. March 2010