066. How to install php gtk2 on linux?

Problem

Installing php-gtk2 on windows is easy - just use the Gnope Installer, and you can have php-gtk2 up and running in less than 5 minutes! ...not for linux.

I just went through two installations of php-gtk2 on linux - one Redhat and the other SuSE.

The installation was not difficult. But the first one took me 2 nights to get it right! Once I figured out the "roadblocks", I was able to install the second one in less than an hour.

For those of you who are going to install php-gtk2 on your linux machine, you may want to refer to the steps below. In particular, I have highlighted some areas that you might want to take note to have a smooth installation.


Solution

Updated on: July 2, 2007

(includes GtkSourceView and GtkExtra)

  1. Download all packages
    First, download all the following packages. Please note the version number.
    • pkg-config-0.21 - a tool for tracking the compilation flags needed for libraries that are used by the GTK+ libraries [download]
    • glib-2.12.4 - the low-level core library that forms the basis of GTK+ and GNOME [download]
    • libpng-1.2.8 - png library [download]
      Note: Choose the .tar.bz2 version which contains configure. Much easier to compile.
    • freetype-2.2.1 - a font engine that provides a simple and easy-to-use API to access font content in a uniform way, independently of the file format. It supports scalable font formats like TrueType or Type 1 natively. [download]
    • fontconfig-2.4.0 - provides Pango with a standard way of locating fonts and matching them against font names [download]
    • cairo-1.2.4 - a graphics library that supports vector graphics and image compositing. Both Pango and GTK+ use cairo for much of their drawing. [download]
      VIP: Please download v1.2.4 (or higher) direct from cairographics.org. DO NOT use the one from ftp://ftp.gtk.org/pub/gtk/v2.10/dependencies/. This one caused me 3 hours to debug! You will find that gtk+ won't compile if you use cairo-1.2.0. The error message said it's problem with pango. But actually it's this cairo-1.2.0 that's causing the problem. Also, I've tried using v1.2.6. Seems to give some errors. S
    • pango-1.16.4 - a library for internationalized text handling [download]
    • atk-1.9.1 - the Accessibility Toolkit [download]
    • gtk+-2.10.12 - the base for php-gtk2 [download]
    • libgnomeprint-2.12.1 - required for gtksourceview [download]
    • gtksourceview-1.6.0 - allows one to display source codes with automatic numbering and syntax highlighting [download]
    • gtk+extra-2.1.1 - contains a number of useful widgets including GtkSheet, GtkPlot and GtkDirTree [download]
    • php-5.2.3 - php5 [download]
    • php-gtk-2.0.0beta - php-gtk2 [download]
  2. X Development Libraries
    Do a quick check on your configuration and make sure you have the X development libraries installed. For example, on Redhat Linux, go to Add/Remove Packages, under Development, make sure "GNOME Software Development" is checked. If it's not, pull out the installation disks and put them in.
  3. Set the necessary environment variables
    If you are using bash, set the following environment variables:
    CPPFLAGS="-I/usr/local/include"
    LDFLAGS="-L/usr/local/lib"
    PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
    LD_LIBRARY_PATH="/usr/local/lib"
    PATH="/usr/local/bin:$PATH"
    export CPPFLAGS LDFLAGS PKG_CONFIG_PATH LD_LIBRARY_PATH PATH

    If you are using csh or tcsh, add the following to .cshrc
    setenv CPPFLAGS "-I/usr/local/include"
    setenv LDFLAGS "-L/usr/local/lib"
    setenv PKG_CONFIG_PATH "/usr/local/lib/pkgconfig"
    setenv LD_LIBRARY_PATH "/usr/local/lib"

    setenv PATH /usr/local/bin:${PATH}

  4. Compile GTK+ first

    Note: For all packages, just use the default configure. The compiled files will reside in /usr/local/lib and /usr/local/include.

    Please compile in the following order:

    1. Compile glib-2.12.4
      tar xvzf glib-2.12.4.tar.gz
      cd glib-2.12.4
      ./configure
      make

      su (log on to root)
      make install

    2. Compile libpng-1.2.12
      bunzip2 libpng-1.2.12.tar.bz2
      tar xvf libpng-1.2.12.tar
      cd libpng-1.2.12
      ./configure
      make

      su (log on to root)
      make install

    3. Compile freetype-2.2.1
      tar xvzf freetype-2.2.1.tar.gz
      cd freetype-2.2.1
      ./configure
      make

      su (log on to root)
      make install

    4. Compile fontconfig-2.4.0
      tar xvzf fontconfig-2.4.0.tar.gz
      cd fontconfig-2.4.0
      ./configure
      make

      su (log on to root)
      make install

    5. Compile cairo-1.2.4
      tar xvzf cairo-1.2.4.tar.gz
      cd cairo-1.2.4
      ./configure
      make

      su (log on to root)
      make install

    6. Compile pango-1.16.4
      tar xvzf pango-1.16.4.tar.gz
      cd pango-1.16.4
      ./configure
      make

      su (log on to root)
      make install
      Note: Most likely you will get some error at this point. Don't worry. It's because you are now in root, and the environment variables as defined earlier are defined in your account, but not in root. Simply type those environment variables in the command line (while logged in as root), and type make install again. Everything should go fine.

    7. Compile atk-1.9.1
      bunzip2 atk-1.9.1.tar.bz2
      tar xvf atk-1.9.1.tar
      cd atk-1.9.1
      ./configure
      make

      su (log on to root)
      make install

    8. Compile gtk+-2.10.12
      tar xvzf gtk+-2.10.12.tar.gz
      cd gtk+-2.10.12
      ./configure
      make

      su (log on to root)
      make install
      Note: Most likely you will get another error here. As above, just add in the required environment variables in root, type make install again, and things should go fine.

      If gtk+ compiles ok, you should now see a gtk-demo in /usr/local/bin. You may test if your gtk+-2.10.6 is ok by running it.

  5. Let's add some additional useful components — GtkSourceView and GtkExtra

    GtkSourceView allows one to display source codes with automatic numbering and syntax highlighting.

    • First compile libgnomeprint-2.12.1
      bunzip libgnomeprint-2.12.1.tar.bz2
      tar xvf libgnomeprint-2.12.1.tar
      cd libgnomeprint-2.12.1
      ./configure
      make

      su (log on to root)
      make install

    • Then compile gtksourceview-1.6.0

      tar xvzf gtksourceview-1.6.0.tar.gz
      cd gtksourceview-1.6.0
      ./configure
      make

      su (log on to root)
      make install

    • Compile gtk+extra-2.1.1

      tar xvzf gtk+extra-2.1.1.tar.gz
      cd gtk+extra-2.1.1
      ./configure
      make

      su (log on to root)
      make install

  6. Compile php-5.2.3
    • First compile php5
      tar xvzf php-5.2.3.tar.gz
      cd php-5.2.3
      ./configure --prefix=/usr/local/php-5.2.3 --disable-cgi
      make

      su (log on to root)
      make install

    • Then create php.ini

      echo extension=php_gtk2.so >> /usr/local/php-5.2.3/lib/php.ini

      /usr/local/php-5.2.3/bin/php-config --extension-dir | xargs echo 'extension_dir=' >> /usr/local/php-5.2.3/lib/php.ini

  7. Compile php-gtk-2.0.0
    • First build configure
      tar xvzf php-gtk-2.0.0beta.tar.gz
      cd php-gtk-2.0.0
      ./buildconf --with-phpize=/usr/local/php-5.2.3/bin/phpize

    • Then compile php-gtk2

      Note: Don't forget the switch "--enable-sourceview --enable-gtkextra" so that gtksourceview and gtkextra will be included.

      ./configure --prefix=/usr/local/php-gtk-2.01 --enable-sourceview --enable-gtkextra --with-php-config=/usr/local/php-5.2.3/bin/php-config
      make

      su (log on to root)
      make install

Congratualations! You have successfully compiled php-gtk2! It's the file: /usr/local/php-5.1.6/bin/php

To make it easier to call php-gtk, let's create a link to this file:
ln -s /usr/local/php-5.2.3/bin/php /usr/bin/php-gtk2

If your environment variable PATH contains /usr/bin, you can now call a php script simply using:
php-gtk2 script.php


Sample Code

Output

Explanation

Add comment


Security code
Refresh