Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Apress Pro PHP-GTK phần 2 ppsx
Nội dung xem thử
Mô tả chi tiết
18 CHAPTER 2 ■ INSTALLING PHP-GTK
Glib: The base libraries for GTK. Glib provides the interfaces for things such as the object
system, the event loop, and threads. See http://www.gtk.org/ for more information about
the GIMP Toolkit and Glib.
Pango: Used for layout and rendering of text in GTK+ 2.0. Pango is responsible for font
handling and internationalizing text.
ATK: The Accessibility Toolkit, a set of interfaces designed to help applications interact with
assistive technologies such as screen readers and alternative input devices. ATK makes it
possible for visually impaired or handicapped users to get the most out of a GTK-based
application.
A few other dependencies exist, but the vast majority of Linux distributions will have
these files installed already. Still, some may be missing from your system. For all of these packages, including GTK, the source is freely available, and the installation process is pretty much
the same. If you need to install any of the dependencies, you should start at the top of the list
and work your way down. That will avoid any wasted time, since one of the packages may be
a dependency for some of the other packages. Once you have downloaded and unpacked the
source code, follow the typical installation procedure:
$> cd /path/to/package/dir/
$> ./configure
$> make
$> make install
Once all the packages are installed, use the pkg-config utility one more time. If everything
looks good, you are ready to move to the next step.
PHP-GTK 2 requires a working PHP 5.1+ installation. Installing PHP is very similar to
installing GTK, except you need to do a little extra configuration to get things set up right. Start
off by downloading and unpacking the source code for PHP 5.1 or higher. Once you have moved
to the PHP directory, you can start setting up the configuration.
PHP-GTK requires PHP to be compiled with CLI mode. CLI mode is enabled by default,
but some developers also like to explicitly disable CGI mode. Doing so helps to avoid some
confusion. If CGI mode is not disabled, two command-line executables will be created: one
for command-line scripts, php-cli, and the other for CGI scripts, php-cgi. If CGI is disabled,
only one executable will be created, php. Therefore, you need to pass the --disable-cgi option.
Next, add a few extensions you will need for development. For this book’s sample application,
we will be using the DOM XML extension, some variety of a relational database management
system (RDBMS), SOAP, and FTP. When you configure PHP, you need to make sure these features
are turned on. You also want to make sure that PEAR gets installed. A few of these options are
already set by default, but it doesn’t hurt to specify them again. When you configure PHP you
need to run the following command:
$> ./configure --with-pgsql --enable-soap --disable-cgi --enable-cli ➥
--enable-ftp --enable-dom --with-pear
Depending on the results of the configure command, you may need to specify a directory
for your RDBMS or PEAR installation. You may also need to specify the location of you LibXML
and zlib installations.
6137ch02.qxd 3/14/06 2:00 PM Page 18
CHAPTER 2 ■ INSTALLING PHP-GTK 19
To specify the location of a directory, you simply add the directory after the configure
command. For example, to tell configure that PEAR should be installed in /usr/share, you pass
--with-pear=/usr/share. The same can be done for your database or XML or zlib extensions.
Chances are you also want to use this same PHP installation for your web applications.
That’s not a problem. Just add the configure commands for your web server.
Once configure has run successfully, continue with the normal build process by running
make and then make install. As usual, you will probably need to have root permissions to run
make install.
■Note Different Linux distributions, package versions, and installation methods can put files in different
places. For instance, some systems may have MySQL installed in /usr/lib/, while others may have it
installed in /usr/local/lib/. The configure tool is usually pretty good about locating files, but sometimes it may need help finding the files on your particular system. That is why it may be necessary to pass
the path to an installation directory or extension, such as --with-libxml=/usr/lib.
So you have PHP 5.1 installed and GTK+ 2 ready to go. You can install PHP-GTK now, right?
Not exactly. While you could go ahead and install PHP-GTK, the installation would be somewhat limited. Don’t misunderstand. You could write some pretty nice applications with a basic
installation of PHP-GTK, but that would be like installing PHP without any database functions.
To get the most out of your PHP-GTK installation, you also need a few supporting packages.
You can install all of these packages using the typical configure, make, make install process.
The desired packages include the following:
Libglade-2.0: A package to help make designing the layout easier.
Scintilla: A powerful text-editing widget.
GdkPixbuf: A package for manipulating and drawing images in a GTK-based application.
GtkHTML: A widget for displaying HTML like a web browser. GtkHTML has a number of
dependencies. Make sure you install all of those first.
Once all of these packages are installed, it’s time to install PHP-GTK. As is the process with
most installations, first you need to download the sources and unpack them. Make sure you
have retrieved the correct version of PHP-GTK. Version 1 will not work with PHP 5 or GTK+ 2.
Building PHP-GTK is slightly different from most Linux installations. After downloading
the sources, you would normally run the configure command. With PHP-GTK, you must build
the configure utility first. To do this, run the buildconf command. This builds a configure utility specifically tailored for your system. Next, run the configure command.
If you decided not to install any of the recommended support packages, you will need to
turn them off by using --disable-<feature>. If you did install these packages, turn them on
with --enable-<feature>. Next, run make and make install.
After running these commands, you will need to update the php.ini file. PHP must load the
PHP-GTK 2 extension so the applications can be run. If you don’t update the php.ini file, you’ll
get an error about nonexistent classes, such as GtkWindow. Simply add extension=php_gtk2.so
(or .dll for Windows) to the Extensions section of your php.ini file. Listing 2-1 shows what the
Extensions section looks like and has some simple instructions.
6137ch02.qxd 3/14/06 2:00 PM Page 19
20 CHAPTER 2 ■ INSTALLING PHP-GTK
Listing 2-1. The Extensions Section of php.ini
;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; Note that it should be the name of the module only; no directory information
; needs to go here. Specify the location of the extension with the
; extension_dir directive above.
Next, test your installation by running one of the demo applications. You can do this by
running the following command:
$> php demos/phpgtk2-demo.php
Now that you have PHP-GTK up and running, you can install a few supporting packages.
Using PEAR and PECL Packages
Regardless of whether you are using Windows or Linux, the remainder of the installation process
is essentially the same. To make your life easier, you are going to use some PEAR packages.
PEAR packages are collections of PHP classes designed to be easily installed, upgraded,
and used by a wide range of users. They are aimed at solving a common problem in the best
and most general way possible. For instance, PEAR::DB is a PEAR package that allows a developer
to change the underlying database for an application without having to change more than one
line of code. You may be pondering the frequency in which you might swap out application
databases. Frankly, the answer is probably never. But if you’re planning on distributing applications to other users, it would be nice to offer users the flexibility of using their database of
choice. By using PEAR::DB, you can give users the freedom to use whichever database system
they like without requiring them to rewrite any parts of the application. We are going to use
PEAR::DB so the code you write will work just as well on a server running MySQL as it will on
a server running PostgreSQL. This will help make your applications easier to install and use,
because there will be fewer restrictions for the end user.
6137ch02.qxd 3/14/06 2:00 PM Page 20
CHAPTER 2 ■ INSTALLING PHP-GTK 21
Aside from providing cross-platform capabilities, many PEAR packages have solved common problems in a very efficient manner. The Gtk_FileDrop package makes it easy to add
drag-and-drop functionality to a PHP-GTK driven application. Using this package saves you
the trouble of having to reimplement that functionality every time you write an application.
PEAR packages are installed, updated, and removed using the PEAR installer, which is
a command-line utility bundled with PHP. Unless you specifically said not to install PEAR during
the PHP 5 installation process, you already have the PEAR installer and a few core packages on
your system. You can see which packages have been installed by running the following command:
$> pear list
You’ll see a list all of the packages that have been installed from the default channel
server, pear.php.net.
A channel is a server that offers PEAR-installable packages. To see which packages have
been installed from another server, you need to pass -c <channel> after the list command.
Just because a package is PEAR-installable doesn’t make it an official PEAR package. The only
real PEAR packages are those that come from the pear.php.net channel. Channels also have
short names to make life a little easier. The short name for pear.php.net is simply pear.
To install a package using the PEAR installer you simply type the following command:
$> pear install <channel>/<package_name>
Substitute the short or long channel for <channel> and the name of the package for
<package_name>. If you are installing a package from your default channel (usually pear), you
can leave out <channel>/ and just use the package name.
Installing PEAR Packages
First, make sure that all the current packages are up-to-date. To do this, execute the following
command:
$> pear upgrade-all
This will check for any packages that have new versions and will update them. PEAR packages are updated and released much more frequently than PHP, so there is a good chance that
one or more of your PEAR packages will need an upgrade.
Next, install a few additional packages. You will install only two now, but you will install
more as the need arises. You’ll install the following packages:
Mail_Mime: A package for sending MIME-encoded email. It makes creating and sending
complex email messages a breeze. Adding attachments or sending email with HTML and
plain text are relatively simple tasks with Mail_Mime.
Console_Getargs: A package designed for letting the user pass command-line arguments.
You will be using it to tell your application to start up in certain states or to provide help
for the user.
To install these packages, type this:
$> pear install -a Mail_Mime
$> pear install -a Console_Getargs
6137ch02.qxd 3/14/06 2:00 PM Page 21