Installation on Mac OS X - step by step

Written by Jonathan Richter

In an attempt to get PHP-GTK2 to work on Mac OS X 10.4, I found very little information and support on that subject. After a lot of failures and errors I got it to work.

Below I'll write every step I took. I am not very comfortable with Terminal and half of the time I have no clue what I am doing. So you can use this information but totally on your own risk. I just worked for me. I hope it will help anybody else too.

please be adviced that doing all steps below takes several hours.

Resources I found helpful:

Step 1 - Get Xcode

Get the newest Xcode (also called: Developer Tools) from Apple. You really need this. Go to Sign in or sign up (for free). Go to Downloads.

On the right in the Downloads Box, click Developer Tools and download the newest Xcode. In my case version 2.4.1, 923 MB big. After downloading, use the installer and follow the instructions.

Step 2 - Get Macports

I started with using Fink, but halfway it failed by not having a package that was needed (GTK 2.6 or higher). I started all over using Macports.

Go to macosforge/InstallingMacPorts.

You already did part of the first step by downloading Xcode. I followed all instructions on that page and it worked fine.

The newest version didn't have a normal Apple installer. So I downloaded this: DarwinPorts-1.3.1-10.4.dmg

Install Macports by double-clicking the installer in the disk image.

Step 3 - Get GTK2 (also called GTK+)

In Terminal, type: sudo port install gtk2

Step 4 - Get PHP5.x

I already had a standard OS X PHP 4.4.4 installation and a PHP5 installation from, but it didn't work out. I deleted my PHP5 installation from Entropy.

If you want to run Apache 1 or 2 with PHP4 or 5, Entropy is absolutely the best place to get it.

In Terminal, type: cd / and sudo port install php5

Take a coffee, this takes a while... about 2 hours on my machine. (Macports installs everything in a folder called /opt. I put the "cd /" to place that folder in the root.)

Step 5 - Prepare for PHP-GTK

On the other tutorial, you see a --disable-libglade as a parameter for installing PHP-GTK. I don't know why they wrote that. Be very sure that you really don't want Glade. Read about it here:

Check out the screenshots too. I installed without Glade but after a day I did it all over to get Glade working too. If you want to continue without Glade, skip the next step.

Step 6 - Get Glade

For some reason, I got errors doing this. Then I tried again the same in Terminal, but now with X11 open in the background with no errors this time. So, open X11 and hide it (apple-h).

In Terminal, type:
cd /opt
sudo port install libglade
sudo port install glade
Take another coffee...

Step 7 - Getting PHP-GTK2

Instead of using current CVS, you might want to use the latest official version from the PHP-GTK2 download page.

Leave X11 open to be on the safe side. phpize and php-config should be both in /opt/local/bin/. Check that before you run this. In Terminal, type:
sudo cvs -d co php-gtk
cd php-gtk
sudo ./buildconf --with-phpize=/opt/local/bin/phpize
sudo ./configure --with-php-config=/opt/local/bin/php-config
sudo make
sudo make install

After it is done, you will see in the output of Terminal a remark about extensions being installed with a path that probably looks like this: /opt/local/lib/php/extensions/no-debug-non-zts-20060613. Apple-c that path or write it down. You will need it later.

Step 8 - Make php.ini ready

In Finder, choose Go > Go To Folder... (or press shift-apple-g) and type /opt/local/etc.

Find the file php.ini-recommended and copy it. Rename the copy to php.ini and open it with - preferably - BBedit.

Find the line extension_dir = "./" and replace it with this: extension_dir = "/opt/local/lib/php/extensions/no-debug-non-zts-20060613" (That path, you copied from the Terminal output in the previous step)

Find the block with all extensions and add this line after them:

Save the file.

Step 9 - Testing

Start X11 and hide it (apple-h) if not already done.

Start Terminal and type:
cd /opt/php-gtk/demos
php phpgtk2-demo.php
The demo should open in a window in X11.

To work with Glade, start it in Terminal like this (with X11 open): /opt/local/bin/glade-2

Step 10 - Making it look better

In my humble opinion: the interfaces in X11 look like crap when you are used to working in OS X. To get other themes, go to to check them out. In order to use one of those, we need to do one more step.

In Terminal, type: sudo port install gtk-theme-switch

After that is ready, download a theme from the link above. Installing it can be done in two ways:

  1. Move or copy the downloaded .tar.gz (without unpacking!) into /opt/local/share/themes/

    Start Glade by typing this in Terminal (with X11 open): /opt/local/bin/switch2

    Press the + sign and click the Install New Theme button. Point to /opt/local/share/themes/<your-new-theme-name>.tar.gz

    Click OK and now your new theme shows up in the list.

  2. Unpack the <your-new-theme-name>.tar.gz and move or copy the new theme folder to /opt/local/share/themes/

    Start Glade by typing this in Terminal (with X11 open): /opt/local/bin/switch2

    The name of the new theme should be in the list.

Again, I got it to work on my machines with above steps. My configs: iMac G5 2.0 GHz/1 GB RAM/OS X 10.4.8 and Mac mini G4 1.42 GHz/512 MB RAM/OS X 10.4.8. Please, fellow Mac users, post here any remarks, tips, tricks, etc. Let's get the PHP-GTK spirit to OS X too! Good hunting!