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
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
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.
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
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 http://svn.php.net/repository/gtk/php-gtk/trunk php-gtk
Now undo that ugly
libtool hack we used:
mv /usr/share/aclocal/libtool.m4.bak /usr/share/aclocal/libtool.m4
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
echo 'extension=php_gtk2.so' >> /etc/php5/cli/php.ini
echo 'extension=cairo.so' >> /etc/php5/cli/php.ini
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: http://gtk.php.net/manual/en/tutorials.helloworld.php 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!
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/php_gtk2.so /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