Updating PHP (and Apache) on PowerPC Macs

Maybe you know the problem, you want to test your new website locally before uploading it to somewhere where it's publicly accessible.

On PowerPC Macs the latest PHP you can get on Leopard is 5.2.x and on Tiger it's even 4.x...
You want the latest and (probably) greatest? Here you go:

Installing Apache and PHP from MacPorts should be done in less than half an hour on an Intel Mac as most of the packages are precompiled already.
On a PowerPC Mac though there are no precompiled packages, and your Mac has to compile them all locally which will take quite some time.
If you want to build 64-bit binaries on a G5, this will lead to errors. Be aware that not all of them are easy to fix.
If you can't get them fixed it's a good idea to ask for help in MacPorts' IRC channel. The guys there are very friendly and they've helped me quite a few times so far.

First you need MacPorts:

  1. If you haven't already, install Xcode (you can find it on your OSX Install Disc)
  2. If you haven't already, install MacPorts

After you have MacPorts installed, open a new Terminal window and run the following commands:

First, let's update the MacPorts port tree so we have access to the latest packages.

sudo port selfupdate

Install PHP (this command installs the latest version of PHP 5.6)

sudo port install php56

...get yourself a cup of coffee...

Set up a basic php.ini
(if you want to use this installation for production, replace "development" with "production")

sudo cp /opt/local/etc/php56/php.ini-development /opt/local/etc/php56/php.ini

Check what version you have installed. If this fails your installation is broken. (optional)

php56 --version

Now let's install Apache

sudo port install apache2

...get yourself another cup of coffee...
Do not run sudo port load apache2 after it finished!

sudo port install php56-apache2handler

...maybe you want one more cup of coffee?
After the installation, enter the following commands like the script tell you to:

cd /opt/local/apache2/modules  
sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php56.so

OK. A base-installation of Apache and PHP is now installed, but how do you run them?
Wouldn't it be nice if you could start and stop them by clicking the checkbox inside your System Preferences?
Of course it would, so let's do that!
The procedure is dependant on which operating system you're using.

On Leopard (or higher)

Make sure Web Sharing is turned off in System Preferences!

For n3rds (or interested people):

If you toggle the checkbox, this enables or disables a LaunchDaemon which takes care of keeping Apache running.
How does it do that you wonder? It runs /usr/sbin/httpd -D FOREGROUND and keeps it running until the LaunchDaemon is killed (when you shut down e.g.)

So let's edit that LaunchDaemon (to take care of our Apache installation):

nano /System/Library/LaunchDaemons/org.apache.httpd.plist

Replace the first entry of the ProgramArguments array (which should be: usr/sbin/httpd) with /opt/local/apache2/bin/apachectl

It should then look like this:


Press Ctrl+O to save and Ctrl+X to leave nano.
You can now turn on Web Sharing again (and it should work).

On Tiger (or lower)

Make sure you have Personal Web Sharing turned off in System Preferences!

For n3rds (or interested people):

If you toggle the checkbox, it only sets the -WEBSERVER- entry in /etc/hostconfig and launches the "/System/Library/StartupItems/Apache/Apache" script with start or stop parameters.
You can also run it yourself if you want:
sudo sh /System/Library/StartupItems/Apache/Apache [start|stop]

First let's adjust the path to apachectl:

sudo mv /usr/sbin/apachectl /usr/sbin/apachectl-13  
sudo ln -s /opt/local/apache2/bin/apachectl /usr/sbin/apachectl

And then adjust httpd.conf

sudo nano /opt/local/apache2/conf/httpd.conf

Append the following line (I've put it after ServerRoot)

PidFile "/private/var/run/httpd.pid"

Press Ctrl+O to save and Ctrl+X to leave nano.
You can now turn on Personal Web Sharing again in System Preferences (and it should work).


You can now enable Web Sharing test your new installation.
If PHP is not working, please check that

For every change you do to the httpd.conf or any other Apache conf, you have to restart Apache to apply them. You can do this by simply unchecking and then checking again the checkbox in System Preferences.

written by: Takashi Yoshi
Tags: PowerPC, HowTo