Installing php-gtk on Debian

So you want to install PHP’s gtk extension. Compared to GTK’s bindings for Perl and Python, PHP’s apparently is under-maintained and is a pain to install as the developers have not accommodated changes in libtool. We will need to install various development packages, temporarily tweak libtool, and then attempt compiling PHP-GTK and enabling it, provided that didn’t fail.

This tutorial was performed on vanilla 64-bit Debian Squeeze 6.0.2 successfully. Something similar will hopefully work for Ubuntu and other Debian derivatives.

First off, become root and install these packages. We’ll be snagging the latest version via subversion and compiling it. We need pear to install cairo, which apparently is a dependency of compiling php-gtk

Assuming you use sudo like myself, you’ll use sudo -i to drop yourself to a root shell. If you have the root account enabled, either log in as root directly or use su - as a normal user to become root.

apt-get install build-essential php5-cli php5-dev libgtk2.0-dev libglade2-dev subversion php-pear

Now get cairo via pecl

pecl install cairo-beta

Unfortunately we temporarily need to hack our libtool configuration. Don’t worry; we’ll restore the old version later. As we’re running as root, we do not need to tweak the file permissions at all here, as other tutorials seem to mention.

cd /usr/share/aclocal
cp libtool.m4 libtool.m4.bak
cat lt~obsolete.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 >> libtool.m4

Check it out, run buildconf, compile, etc. This is the most important part. If buildconf or configure do not finish successfully, undo the above change (move on to my next step) and reply demanding me to update this tutorial. Please give as much information regarding your distro’s setup and the steps you have taken as possible.

svn co php-gtk
cd php-gtk
make install

Now undo that ugly libtool hack we used:

mv /usr/share/aclocal/libtool.m4.bak /usr/share/aclocal/libtool.m4

Enable cairo and php-gtk extensions by adding the necessary lines to the php.ini for command-line. We are not creating .ini’s for each .so in the /etc/php5/conf.d/ folder (as php extensions normally do on Debian) because then php5-cgi will attempt loading them and web pages will generate error 500’s as they try to connect to X-Windows

echo '' >> /etc/php5/cli/php.ini
echo '' >> /etc/php5/cli/php.ini

Ensure that gtk is properly installed. We shouldn’t need to worry about cairo being broken since pecl shouldn’t have failed.

php -m | grep gtk

This should give something such as the following if all goes well. If it does not list php-gtk, we have failed.

root@adore:~# php -m | grep gtk

To further verify everything is working correctly, you should probably test a sample GTK hello world as described here: or just run the php-gtk software you sought this tutorial for anyway. This is unnecessary if you are installing php-gtk just to get a tool such as the Phoronix Test Suite to work.

You should be done! Comments are much appreciated!

Uninstalling php-gtk

Uninstall by killing the shared library/header files and then removing the line from the cli php.ini. (Due to your shell’s noclobber possibly being enabled, we are first outputting a gtk-less php.ini to a separate file and then moving it on top of the one including gtk)

rm -rf /usr/lib/php5/20090626/ /usr/include/php5/ext/php_gtk2/
grep -v gtk /etc/php5/cli/php.ini > orig_php.ini
mv orig_php.ini /etc/php5/cli/php.ini

One comment

  1. lmx says:

    Thanks for the Article 😉
    I have an error, after installling cairo beta and hacking on libtool…

    i have used for $PHPIZED environment variable /usr/bin/phpize…it give some errors….afther that i type :
    ./buildconf –with-phpize=/usr/bin/phpize, it runs well
    ./configure runs well too.
    I am able to run ./buildconf and ./configure…but when I type make…i have an error:

    /bin/bash /root/php-gtk/libtool –mode=compile cc -I/root/php-gtk/main -I. -I/root/php-gtk -DPHP_ATOM_INC -I/root/php-gtk/include -I/root/php-gtk/main -I/root/php-gtk -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/php5/ext/cairo -I/usr/include/libxml2 -I/usr/include/libglade-2.0 -DHAVE_CONFIG_H -g -O2 -c /root/php-gtk/main/phpg_support.c -o main/phpg_support.lo
    libtool: compile: cc -I/root/php-gtk/main -I. -I/root/php-gtk -DPHP_ATOM_INC -I/root/php-gtk/include -I/root/php-gtk/main -I/root/php-gtk -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/php5/ext/cairo -I/usr/include/libxml2 -I/usr/include/libglade-2.0 -DHAVE_CONFIG_H -g -O2 -c /root/php-gtk/main/phpg_support.c -fPIC -DPIC -o main/.libs/phpg_support.o
    /root/php-gtk/main/phpg_support.c: In function ‘phpg_init_object':
    /root/php-gtk/main/phpg_support.c:276:42: error: ‘zend_class_entry’ has no member named ‘default_properties’
    /root/php-gtk/main/phpg_support.c: In function ‘phpg_register_class':
    /root/php-gtk/main/phpg_support.c:314:4: error: ‘zend_class_entry’ has no member named ‘builtin_functions’
    /root/php-gtk/main/phpg_support.c: In function ‘phpg_register_interface':
    /root/php-gtk/main/phpg_support.c:367:7: error: ‘zend_class_entry’ has no member named ‘builtin_functions’
    make: *** [main/phpg_support.lo] Error 1

    Do you know whats wrong??
    i made afther that an svn update…it gives me an error related with gnome-keyring…but it ends with an:
    At revision 328931.(it it seems to be actualized…)

    Thanks in advance.


Leave a Reply

Your email address will not be published. Required fields are marked *

four × = thirty six