These instructions may work on other Linux distributions as well. Please note this howto is provided in the hope that it is useful, but with no warranties or guarantees of any kind. Your use of the information or advice given in this howto is solely at your own risk and responsibility. We will not be liable for any losses or damages (like loss of data). We cannot guarantee the instructions will work flawlessly, will be error-free or not cause any problems to your operating system. I'd recommend you make a backup before proceeding, and you should make regular backups in general anyway. For full OS backups (including all data on it), consider looking at Clonezilla. By proceeding, you are indicating that you fully understand the risks in doing so.
Windows users can easily run PHP-GTK applications because binaries are available for Windows users - the most recent official binary available on the PHP-GTK website is, as of writing, 2.0.1. You can download an unofficial, more up-to-date Windows binary compiled by a user often contributing to the project "auroraesrose" here. All you need to do is unzip and run. It's as simple as that. You can right-click on any PHP-GTK file and then execute it with the PHP executable from the unzipped folder.
Installing PHP-GTK on Ubuntu is not as easy as it should be primarily because certain packages need to be installed beforehand and a few other things - but it's relatively easy. If you know how to use a Terminal window, you'll be on your way.
There's a few things we need to install beforehand:
- subversion (for downloading the Cairo extension using svn)
- git-core (for downloading PHP-GTK using git)
- php5-dev: This is for compiling additional modules. You won't be able to install PHP-GTK without having php5-dev installed.
- libglade2-dev: See more about Glade here. Note: No need to install libglade2-0, you should already have this installed on your system. Libglade2-0 is to load external .glade files into your applications. For more information about the Glade IDE, see the link above.
- pecl-cairo: Read more about Cairo here.
Apart from that, we have to concatenate a few files back otherwise we'll also run into problems while trying to execute the ./buildconf and ./configure commands prior to installing PHP-GTK.
I do want to point out that on the PHP-GTK website it states the latest PHP-GTK source is available on the SVN server, but the latest source is available via git - which is why we need to have git installed so we can download the php-gtk source over git.
Common errors occurring with PHP-GTK installation.
If you simply download PHP-GTK (either the latest via SVN or downloading the source via the PHP-GTK website) without installing the necessary dependencies above, when executing ./buildconf, you'll come across this error: configure: error: PHP-GTK 2.x requires GLib 2.6.0 or higher.
Let's get started.
1. Install the dependencies.
sudo apt-get install build-essential subversion php5-cli php5-dev libgtk2.0-dev libglade2-dev git-core
svn co http://svn.php.net/repository/pecl/cairo/trunk pecl-cairo cd pecl-cairo phpize ./configure make sudo make install
The newer libtool.m4 has been split into different files. To be able to compile the PHP-GTK source prior to install (i.e. 'make' and 'sudo make install'), you'll need to concatenate these files back into the libtool.
Note: This may only apply to Ubuntu. If you have another (non-Ubuntu derivative) Linux distribution installed, or you have Ubuntu but you compiled and installed PHP yourself, try skipping step 3 below and go right ahead to compiling and installing PHP-GTK and see if it works. If not, come back and complete step 3.
3. Concatenate the files back into the libtool.
cd /usr/share/aclocal sudo cp libtool.m4 libtool.m4~backup sudo chmod 777 libtool.m4 sudo cat lt~obsolete.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 >>libtool.m4 sudo chmod 644 libtool.m4 cd ~/
Now let's go ahead and download PHP-GTK. Download the latest source from git (very latest is via git, not svn, unlike what the outdated PHP-GTK Downloads page says). An issue that was later rectified in PHP-GTK which would otherwise cause error: duplicate static to be returned when running the make command prior to installing PHP-GTK - hence we need to download the latest PHP-GTK source from git.
4. Download and install PHP-GTK.
git clone git://github.com/php/php-gtk-src.git ./buildconf ./configure make sudo make install
PHP-GTK will now be installed at this point. All you have to do now is find where your php-cli php.ini configuration file is and add the extensions to the Dynamic Extensions section of the PHP configuration file (which is above the Module Settings section) so when you execute PHP-GTK applications via the Terminal the extensions can be found.
You can find where the php.ini file is by searching for it via the File Manager on your Linux distribution, just check which php.ini corresponds to the php-cli folder. It may, however, be located in /etc/php5/cli/php.ini. You can edit the file using gedit or vim, using:
sudo gedit /etc/php5/cli/php.ini
Make sure you're in the directory where the PHP-GTK source is located. This is likely in the home directory, so in this case change directory to there:
$window = new GtkWindow();
$window->set_title('My first application!');
$window->connect_simple('destroy', array('Gtk', 'main_quit'));