PHP Apache Module
- Introduction
- Installation Instructions
- Update Instructions
- Examples
- FAQ
- Additional Information
- 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 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 MySQL and PostgreSQL databases
- the PDFLib PDF library
- 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
- FTP client access
- exif digital camera image metadata support
- transparent session id propagation (--enable-trans-sid) option
- mcrypt encryption functions
- mhash hashing functions
- sockets extension (experimental!)
- iODBC database support
- XML-RPC support (back in after I had to remove it in a previous release)
- GNU gettext
- CLI Version
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 your code does not run on PHP5 and requires PHP4, please fix your code...
- If your hosting provider does not support PHP5, consider changing the provider. If a hosting provider lags behind with software releases, that’s a bad sign.
- If your web server runs an older Mac OS X release, please upgrade the OS.
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.
- PPC and Intel: The PHP5 package version 5.1.4 and higher is the recommended version.
- PPC and Intel: The PHP5 package version 5.1.4 and higher for Apache 2 can be used with Apache 2 installed into /usr/local/apache2, built from source according to these instructions. Also see the details in this forum discussion.
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 | |
- Download the appropriate installation package from the list above.
- Unpack the compressed .tar.gz file but DO NOT USE StuffIt Expander, use Apple’s BOMArchiveHelper or the command line.
- 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 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
- 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.
(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.
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
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.
You have to use the full path /usr/local/php5/bin/php and not just php. That will invoke Apple's original PHP module.
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.
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
{\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!
Yes. It is included in the package in /usr/local/php5/bin, along with many other goodies.
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
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
- 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
