This is an update to a document I wrote 4 years ago about compiling PHP-GTK on any Unixesque system you could get your hands on, but this one only for Ubuntu 10+. At the time of writing I was using a freshly installed Ubuntu 10.10 system to do this, so for the sake of completeness we are going to assume the system has nothing we need as though it was fresh off the installation disk a few minutes ago.

Here is an overview of what we have to do. The order is very important. If you do not follow the proper order things will not work right. This becomes very important when it comes time to build PHP-GTK itself.

  • Install subversion.
  • Install PHP5.
  • Install GTK development packages.
  • Install the Cairo module for PHP.
  • Get, patch, and compile PHP-GTK.

And here is how we do it. You are going to need a terminal window.

 

Install Subversion.

We need to install subversion because we are going to download the freshest copies of Cairo and PHP-GTK2. Subversion is in our package repository, so all we have to do is:

Command Line Interface (CLI):
$ sudo apt-get install subversion

 

Install PHP5 and GTK development packages.

Everything PHP-GTK depends on (which the exception of Cairo) is in our package repository.

Command Line Interface (CLI):
$ sudo apt-get install php5-cli php5-dev libgtk2.0-dev

This command should inform you that in order to install these three packages, you need to install about 50 others. Accept the dependencies, sit back, relax, and let it all install.

 

Install the Cairo module for PHP.

Next we need to build the Cairo module for PHP as PHP-GTK depends on it. Grab the latest source for Cairo using subversion.

Command Line Interface (CLI):
co http://svn.php.net/repository/pecl/cairo/trunk cairo

Now we build it. Move into the Cairo directory and compile it.

Command Line Interface (CLI):
$ phpize

Command Line Interface (CLI):
$ ./configure

Command Line Interface (CLI):
$ make

Command Line Interface (CLI):
$ sudo make install

Now we need to load it in PHP. Edit the file /etc/php5/cli/php.ini in your favourite editor (with root permissions), zip down to the end and add the line:

extension=cairo.so

Save and confirm that it worked by checking that cairo is listed in PHP with the command:

Command Line Interface (CLI):
$ php -m

 

Get PHP-GTK.

Using subversion again we will download the latest PHP-GTK.

Command Line Interface (CLI):
co http://svn.php.net/repository/gtk/php-gtk/trunk php-gtk

 

Patch PHP-GTK.

We need to patch the PHP-GTK source because Ubuntu is using a version of libtool which appears to be different than what other distributions are using. If you try and compile PHP-GTK without patching it you will see errors similar to these:

configure.in:77: warning: LTOPTIONS_VERSION is m4_require’d but not m4_defun’d
aclocal.m4:2912: LT_INIT is expanded from…
aclocal.m4:2947: AC_PROG_LIBTOOL is expanded from…
configure.in:77: the top level
configure.in:77: warning: LTSUGAR_VERSION is m4_require’d but not m4_defun’d
configure.in:77: warning: LTVERSION_VERSION is m4_require’d but not m4_defun’d
configure.in:77: warning: LTOBSOLETE_VERSION is m4_require’d but not

configure.in:51: error: possibly undefined macro: AC_MSG_ERROR
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure:4266: error: possibly undefined macro: AM_PATH_GLIB_2_0
configure:4397: error: possibly undefined macro: AM_PATH_GTK_2_0

./configure: line 4242: syntax error near unexpected token `debug,’
./configure: line 4242: `PHP_GTK_ARG_ENABLE(debug, whether to include debugging symbols,’

Which long story short, are no good. The good news is the patch is really tiny and I have it for you to download right here. Go back to your terminal and move into the PHP-GTK source we downloaded from the subversion.

Command Line Interface (CLI):
$ wget http://squirrelshaterobots.com/files/phpgtk/phpgtk-buildfix-20090105a.diff

Command Line Interface (CLI):
$ patch -p1 < phpgtk-buildfix-20090105a.diff
patching file build2/build2.mk
Hunk #1 succeeded at 10 with fuzz 2.

You MUST do this patch before executing any of the compile scripts in PHP-GTK, or else the autotools chain will make cache files that render the patch file ineffective.

 

Compile PHP-GTK.

At this point we should be ready to compile PHP-GTK.

Command Line Interface (CLI):
$ ./buildconf

Command Line Interface (CLI):
$ ./configure

Command Line Interface (CLI):
$ make

Command Line Interface (CLI):
$ sudo make install

Once the compiling is done, edit theĀ /etc/php5/cli/php.ini again in your favourite editor (with root permissions), and add this line underneath the one you added earlier:

extension=php_gtk2.so

Verify that PHP-GTK2 is being loaded by checking the module list again.

Command Line Interface (CLI):
$ php -m

You should now see both cairo and php-gtk in the PHP module list. That means you are good to go.

 

Last minute notes.

Right now we have Cairo and PHP-GTK being loaded by Ubuntu’s default CLI php.ini file. This means every time PHP is run from the command line PHP-GTK will be loaded. This will not work very well if we are using PHP from something like a recovery console or over SSH. To get around this we create a new PHP.INI just for PHP-GTK applications, which I will cover in another post over the weekend.