PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 66: How to install php gtk2 on linux?
Written by kksou   
Friday, 20 October 2006
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
Explanation

User reviews   Average user ratings:    3.5   (from 8 users)
  1. Klopper from Netherlands
    January 01, 2008 5:20am

    I have tried the 'tutorial', but now PHP-GTK2 is returning the message 'Could not startup.'. Why is this, and how do I solve this problem?

  2. kksou
    January 01, 2008 5:20am

    Which platform are you running? Can you give a bit more details? Any other error messages?

  3. Kyle
    January 01, 2008 5:20am

    Worked great, thanks.

  4. Sebastián Marconi from Argentina
    January 01, 2008 5:20am

    @Klopper: Do you have an X server enviroment in that server? If you are connecting throw ssh you should try with the -X argument.

  5. Marc from Germany
    January 01, 2008 5:20am

    i don't know much about compiling stuff on linux. anyway, on my linux-machine (ubuntu,gutsy,64 bit) ...


    (1) ... i had to play around with the library-path mentioned in step 3 (LD_LIBRARY_PATH="/usr/local/lib"). i used LD_LIBRARY_PATH="/usr/local/lib:/usr/lib" instead.

    (2) ... and in step 7, i had to use "--with-sourceview --with-extra" to get the extensions work (instead "--enable-sourceview --enable-gtkextra")

    hope this might help somebody.

  6. Hans Meier
    January 03, 2008 8:21pm
    Tim from Germany

    Hi Marc from Germany,

    I also had some issues compiling PHP-GTK on Ubuntu Gutsy Gibbon 7.10. I wasn't able to post the tutorial here which I used to get it to work so I've posted it here: http://www.kksou.com/php-gtk2/PHP-GTK2-Help/8-test1.php#8

    Best regards and good luck,
    Tim

  7. M Drake
    June 19, 2009 5:28pm

    Trying to get our app running on Ubuntu Jaunty. Tried all sorts of instructions, including a form of these, but regardless, while I can get successful install of php-gtk2, I can't get gridlines or tooltips to work.

    On the other hand, we found a amd-64.deb of the install that works just fine on our 64-bit Unbuntu installs.

    Any ideas?

  8. M Drake
    July 15, 2009 6:11pm

    Found the answer to my own question. Existing source file on the php-gtk2 site is missing some libraries. See the php-gtk2 dev mailing list.

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved