|
Object Oriented PHP-GTK2 - Configuring PHP for GTK
Object Oriented PHP-GTK2 - Configuring PHP for GTK
|
||||
|
OOPS Site
Compile
Configuring PHP for GTKSetting up the environment for PHP to work right at all times Topic: Compiling PHP-GTK2 (View All Tutorials) Before you can use PHP-GTK, PHP needs to load the module. This is done via the php.ini file. Windows users should read this instead. Why a PHP-GTK Config?On Unix based systems, it is a good idea to have a separate PHP config file just for GTK. Why?
[bob@kathryn ~]$ php Could not startup.
[bob@kathryn ~]$ php (-:61599): Gdk-WARNING **: Connection to display localhost:10.0 appears to be untrusted. Pointer and keyboard grabs and inter-client communication may not work as expected.
Moral of the story? Do not use Apache's PHP.INI, do not use the PHP-CLI.INI. Use a special config file just for GTK. It is not hard to setup.
Create The Config, and GoFirst thing, run `which php`. If it does not say /usr/bin/php as on some systems it might say /usr/local/bin/php instead, then you should create a symbolic link. [root@kathryn /]# ln -s /usr/local/bin/php /usr/bin/php Now open your favourite text editor and paste the following into a new file. ; This is a default PHP.INI (/etc/gtk/php.ini) for GTK Applications. ; Bob Majdak Jr
The highlighted line, extension_dir, this is different from system to system. You will need to put the path to your extension dir in there instead. To find out, you can use this command.
Also, see the line that is extension = "php_gtk2.so"? Look in your extension_dir and see what .so files you have in there. If you have gettext.so add an extension line for it after the PHP-GTK one. Gettext is the important one because that is what allows you to create translations for your applications. Add your other modules if you want, such as MySQL and the like.
Now, save this file as /etc/gtk/php.ini. You might have to create the /etc/gtk directory. You can test if you were successful with this command. [bob@kathryn ~]$ php -c /etc/gtk/php.ini -i | grep GTK GTK+ support => enabled GTK+ v => 2.10.6 This means everything is good to go. If it did not tell you GTK+ support is enabled then you did not install successfully.
Using the Correct ConfigNow PHP programs on the CLI will use the default CLI config, and only programs which are told they need GTK will use the GTK config. This is very good. [bob@kathryn ~]$ php -i | grep Loaded Loaded Configuration File => /usr/local/etc/php-cli.ini [bob@kathryn ~]$ php -c /etc/gtk/php.ini -i | grep Loaded Loaded Configuration File => /etc/gtk/php.ini "But Bob," you are probably saying, "that looks like a pain in the arse to type every time." You are right! Instead of typing this every time we want to run a program, we tell the program to do it. You will notice at the top of all my code codes, one line which actually comes before the opening <?php marker. This line is called a hashbang (or shebang). #!/usr/bin/php -c/etc/gtk/php.ini See the first line of code in this tutorial for example. Notice /usr/bin/php, the symlink I told you to create earlier, and the lack of a space between -c and /etc/gtk/php.ini. This line should be placed at the top of all programs you want to use GTK. With this line if the file has the proper permissions (aka 755) then instead of doing something like this: [bob@kathryn ~]$ php -c /etc/gtk/php.ini test.phpg We can do this: [bob@kathryn ~]$ ./test.phpg And if test.phpg was located in a PATH directory such as /usr/bin then we could do: [bob@kathryn ~]$ test.phpg You could even rename the file to not have the .phpg file extension if you wanted.
Was this document helpful? I appreciate your feedback. i can has web two point ooh // copyright © 2007-2008 bob majdak jr
[ xhtml css | firefox ie7 opera ] |
||||