How to: PHP 5.3 with PHP-GTK and Cairo on Linux Mint 9

At the moment there are some minor problems when trying to get a working installation of PHP with GTK running on Ubuntu based systems. Here is a quick walk through of how you can get this all set up with the trunks from GTK and Cairo and the official package for php-cli in 10 easy steps. This installation was originally done on Linux Mint 9 but should work with most Ubuntu based Linux distributions.

  1. First of all install all the required packages, for this run the following command:
    florian ~ $  sudo apt-get install php5-cli php5-dev libcairo2-dev libgtk2.0-dev
    This will get you the current official package for PHP5 (5.3.2 at the time of writing) and then install all the things you need to build your Cairo and PHP-GTK extensions.
  2. After these have been installed, go to your home directory and checkout the latest Cairo and PHP-GTK trees from SVN:
  3. Next build and install the Cairo extension, you need to do this first because it is a dependancy of PHP-GTK. For this do the following:
    florian ~ $ cd cairo/
    florian ~/cairo $ phpize
    florian ~/cairo $ ./configure
  4. Now you need to apply a little fix to the Makefile for Cairo to compile successfully (this is from Matthew Turland). Just open ~/cairo/Makefile with a text editor (nano or gedit, for example) and then find the line CFLAGS = -g -O2 and replace it with this: CFLAGS = -g -O2 -DCOMPILE_DL_CAIRO.
  5. Now you are ready to compile the Cairo extension, for this run make and make install like so:
    florian ~/cairo $ make
    florian ~/cairo $ sudo make install
    Done. You have now successfully built the Cairo extension for php.
  6. Next you need to compile PHP-GTK. For this to work you will first need to apply a patch to the source tree, because there are some issues with the locations and names of the m4 libraries. Create the new file ~/php-gtk/ubuntu-fix.patch with the following content (this is from Bob Majdak):
    diff -ur php-gtk/build2/ php-gtk-bob/build2/
    --- php-gtk/build2/ 2005-10-10 14:34:39.000000000 -0400
    +++ php-gtk-bob/build2/ 2009-01-05 10:46:29.000000000 -0500
    @@ -10,6 +10,7 @@

    aclocal.m4: acinclude.m4
    @echo rebuilding $@
    + cat /usr/share/aclocal/lt~obsolete.m4 /usr/share/aclocal/ltoptions.m4 /usr/share/aclocal/ltsugar.m4 /usr/share/aclocal/ltversion.m4 >> ./build/libtool.m4
    cat acinclude.m4 ./build/libtool.m4 php_gtk.m4 > $@
  7. After saving, run the following two commands inside the ~/php-gtk directory.
    florian ~/php-gtk $ patch -Np1 --ignore-whitespace -i ./ubuntu-fix.diff
    florian ~/php-gtk $ patch -Np2 -F13 -ignore-whitespace -i ./ubuntu-fix.diff
    This will make sure PHP-GTK can find the libtool libraries it needs.
  8. Now we can build the php-gtk extension. For this you have to run buildconf and configure followed by the make. For this use the following commands:
    florian ~/php-gtk $ ./buildconf
    florian ~/php-gtk $ ./configure
    florian ~/php-gtk $ make
    florian ~/php-gtk $ sudo make install
    Done. You have (hopefully) successfully built the latest PHP-GTK extension.
  9. The only thing left to do now is make PHP actually load the two new libraries. For this you will need to locate your php.ini, you can find out where this is by running php --ini from the terminal. Normally you will however find it in /etc/php5/cli/php.ini. Open this as root, for example with
    florian ~ $ sudo nano /etc/php5/cli/php.ini
    florian ~ $ sudo gedit /etc/php5/cli/php.ini
    Here find the line ; Dynamic Extensions ; and at the bottom of the section that is following it (All the lines beginning with ";" are comments, they should explain you how to load extensions) append the following:
    ; Cairo
    ; PHP-GTK 2
  10. Check that PHP does load the extensions as should be by running php -m which shows you a list with all the loaded modules, these should now include cairo and php-gtk. If this is all fine go and clean up your home directory, for this just do the following:
    florian ~ $ rm -rf ~/cairo
    florian ~ $ rm -rf ~/php-gtk

Congratulations, you are all done! Now go and enjoy your new PHP-GTK beauty!


malformed patch


Thanks for your procedure to install PHP-GTK and Cairo in Linux Mint. Following your instructions I installed Cairo but I couldn't install PHP-GTK. It seems that there is something with the patch avoiding compilation:

alfredo@alfredo-laptop ~/php-gtk $ patch -Np1 --ignore-whitespace -i ./ubuntu-fix.diff
patching file build2/
patch: **** malformed patch at line 6: aclocal.m4: acinclude.m4


Opções de exibição de comentários

Escolha seu modo de exibição preferido e clique em "Salvar configurações" para ativar.