Php – OSX Default Apache + MacPorts PHP

apache-2.2mac-osxmac-osx-serverPHP

If possible, I'd like to retain the default Apache installation and simply direct it to use a different version of PHP built/installed using MacPorts. Is this possible (and if so, is there a straightforward process for setting this up)?

I know Apache wants me to specify the PHP module to load, but its not clear to me how I might have it use a different PHP installation (if thats even possible). Do I need to compile a new apache module that would somehow point to my copy of PHP built with MacPorts? Any clarification on what I need to do would be greatly appreciated!

Update: What about enabling FastCGI and running PHP via that instead of an apache module? I know there are tradeoffs between the two approaches, but would this be a possibility or would I run into similar problems?

Best Answer

Macports PHP libphp5.so is usually not compatible with OSX's default Apache system. Here's what happens on my macosxserver.

# /etc/apache2/httpd.conf
LoadModule php5_module /opt/local/apache2/modules/libphp5.so

Attempt to start the server

~> sudo /usr/sbin/apachectl -k start
httpd: Syntax error on line 118 of /private/etc/apache2/httpd.conf: 
Cannot load /opt/local/apache2/modules/libphp5.so into server: dlopen(/opt/local/apache2/modules/libphp5.so, 10): 
Library not loaded: /opt/local/lib/libaprutil-1.0.dylib\n  Referenced from: /opt/local/apache2/modules/libphp5.so\n  
Reason: Incompatible library version: libphp5.so requires version 5.0.0 or later, but libaprutil-1.0.dylib provides version 4.0.0

You can easily compile PHP to use your default Apache installation, by setting the path to your default apxs.

# In PHP source directory
./configure --with-apxs2=/usr/sbin/apxs

Of course, (re-)compiling PHP might be more work then you wish to inherit. The easist way would be to accept Macport's Apache installation, and adjust your osxserver to use /opt/local/apache2 as your default HTTPD service.