PHP Apache Module
- Introduction
- Installation Instructions
- Update Instructions
- Examples
- FAQ
- Additional Information
- Alternatives
- Build Instructions
- Acknowledgements
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 MySQL and PostgreSQL databases
- the cURL library for various communications protocols
- the GD image creation library (with PNG, JPEG, PostScript Type 1 and TrueType font options).
- the expat XML parser and WDDX support
- XSLT transformations
- LDAP access
- the IMAP client library
- mcrypt encryption functions
- GNU gettext
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:
An older PHP 5.2 package:
Here’s an older, unsupported and probably insecure version for 10.4:
To install the package:
- Download the appropriate installation package from the list above.
- 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.
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
- The phpinfo example.
- An example of the image creation abilities. (view source)
- Here is another one, this is an Aqua button generator. (view source)
- Here is the iTunes track I’m currently listening to) (view source, you also need to run this AppleScript in an endless loop)
- Demo of the Type 1 font rasterizer feature. (view source)
- Another one Also look at the t1utils package to convert your Mac PS fonts to the UNIX format required by the rasterizer.
- The clock PDF example from the PHP manual section on PDFLib
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.
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
_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.
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.
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.
Yes but you have to disable Apple’s PHP in the Server Admin application before installing this package.
{\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!
Yes. It is included in the package in /usr/local/php5/bin, along with many other goodies.
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
- Check out the book
PHP Advanced: Visual QuickPro Guide
. - www.php.net is obviously the best source of information. Check out the excellent tutorial as well as the reference manual.
- Both MacPHP.net and PHPmac.com are web sites dedicated to PHP on Mac OS based systems.
- If you are looking for PHP for Apache 2, take a look at the Server Logistics web site.
- Sheri German has a series of very useful tutorials and tips about integrating MySQL / PHP with GoLive
- Apple’s Developer Connection has a page for PHP developers
- Carsten Klapp has some information about activating PEAR for version 4.1 of the module
- Erik Wrenholt wrote a nice, simple PHP application to get you started with PHP and MySQL
- Wincent Colaiuta wrote an interesting article about
Mac OS X for Web Developers
Alternatives
There are other PHP distributions for Mac OS X users:
- Apple includes PHP5 since Mac OS X 10.5. You have to enable it in
/etc/apache2/httpd.conf. On Mac OS X Server, you can enable it in the Server Admin application ant it’s probably enabled by default. - MAMP is another distribution that does not interact with Apple’s Apache webserver, includes MySQL and 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.
- Another alternative is Zend Server, which comes in a Mac OS X version and is free in the Community Edition.
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
- Straumann AG for sponsoring an extensive Mac OS X Leopard / Apache 2 update by Joachim Fornallaz
- Andy Liyanage and Jason Justman for access to powerful hardware for the build process
- Finlay Dobbie for cool preprocessor trick tips
- the PHP development team for the hard work they’re doing
- ACADEMY GmbH for sponsoring FrontBase support
- Micka Moggia of QX Förlag AB for sponsoring Apache 2 support
- everyone who sent a donation
