How to install PHP-GTK on Ubuntu 12.04 / in Deb...

  1. 15-08-2012, 15:26 #1
    Ben Stones's Avatar
    Ben Stones is offline Administrator
    Send a message via MSN to Ben Stones  Send a message via Skype™ to Ben Stones
    Join DateJan 2007LocationUnited KingdomPosts3,946

    Default How to install PHP-GTK on Ubuntu 12.04 / in Debian?



    These instructions may work on other Linux distributions as well. And, as always, you must only make use these instructions and any advice at your own risk and responsibility. We cannot be liable for any losses or damages (like loss of data). We hope to be as helpful as possible with this howto, but we cannot guarantee the instructions will work, 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.

    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.
    Code:
    sudo apt-get install build-essential subversion php5-cli php5-dev libgtk2.0-dev libglade2-dev git-core
    2. Download pecl-cairo.
    Code:
    svn co http://svn.php.net/repository/pecl/cairo/trunk pecl-cairo
    cd pecl-cairo
    phpize
    ./configure
    make
    sudo make install
    ( What is phpize?)

    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.
    Code:
    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 ~/
    Note: "cd ~/" changes the directory back to the home directory (~/) - if you try and fetch the php-gtk source below in /usr/share/aclocal you'll be given a "Permission Denied" error.

    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.
    Code:
    git clone git://github.com/php/php-gtk-src.git
    ./buildconf
    ./configure
    make
    sudo make install
    For your information - You can find where the PHP-GTK and Cairo extensions are installed by executing php-config and looking at the extensions_dir line.

    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:

    Code:
    sudo gedit /etc/php5/cli/php.ini
    5. Add the PHP-GTK and Cairo Extension to "Dynamic Extensions".
    Code:
    extension=php_gtk2.so
    extension=cairo.so
    Once done, save the file, quit gedit or :q to exit vim (or :wq if you're in the file at the time to save the changes and quit vim). Now you can execute a PHP-GTK test application to see if everything works.

    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:

    Code:
    cd ~/php-gtk
    6. Execute the PHP-GTK demo application.
    Code:
    php demos/phpgtk2-demo.php
    You can also create your own test PHP-GTK application and execute it the same way - a .php extension for your PHP-GTK application will do fine.

    PHP Code:
    <?php

        $window = new GtkWindow();
        $window->set_title('My first application!');
        $window->connect_simple('destroy', array('Gtk', 'main_quit'));

        $window->show_all();

        Gtk::main();

    ?>
    In this very basic PHP-GTK application, only a simple PHP-GTK window will be displayed as shown below. The $window->connect_simple() method is to tell PHP-GTK we want to quit the entire application when the window is closed - because when a window is closed, the  destroy signal is fired. The main_quit() method which is a part of the  Gtk class quits the application by terminating the main loop (Gtk::main() being the main loop) that keeps the application active
    http://forums.eukhost.com/f15/how-install-php-gtk-ubuntu-12-04-debian-17378/#.UXfE7pAW2Kk

转载于:https://my.oschina.net/u/438320/blog/125306

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值