PHP Implementation of the Google API: Howto
IntroductionThis is an easily customizable, PHP implementation of the Google API. It utilizes Pear packages; therefore, the PHP SOAP extension doesn't need to be configured/installed on the web server. Go directly to the download section or read on...
PHP, Pear & SOAPThere are basically three approaches to successfully running a PHP implementation of the Google API. Essentially, it boils down to what implementation of SOAP you wish to use
If SOAP isn't installed on your system with PHP, you can use the Pear SOAP package found on Pear's website. What's even better is you don't need root privileges to get SOAP (Pear) running. All you have to do is drop the appropriate files in the right directories and you're good to go. PEAR is a framework and distribution system for reusable PHP components. Various contributors donate code in a uniform manner to ensure Pear and PHP's overall value and usefulness; thus, we don't have to worry about Pear disappearing in the near future. With Pear, there are three common ways to install new packages:
Dropping this package in a directory and changing configuration variables (conf.php), would essentially be a manual installation. You have to be careful with manual installs since certain packages call other packages using specific paths. Should there be an incorrect path, you may end up with a useless set of packages. Like many other Pear packages, SOAP has dependencies which have dependencies. You have have to make sure all respective packages are in place; luckily, I have set up the directory of packages for you in pear/. Paradoxically, this is fortunate and unfortunate at the same time for we want contributors to fix bugs and add functionality yet we as programmers wish to spend less time making upgrades (unless we're good enough to create automatic update scripts.)...i.e., don't be lazy and make upgrades. To obtain the latest versions of the necessary packages, wget the latest versions from the Pear website (for example 'wget http://pear.php.net.get/SOAP'). Be sure to unpack the files in the appropriate location(s); use the baseinstalldir and/or name attributes from the package.xml file. (may take some experience and/or experimentation).
The current versions installed.
Our SetupThere are four files and one directory bundled with this package. search.php, conf.php, main.css, help.html and pear/. search.php is the user interface; it's where the user(s) will the queries. conf.php contains the configuration settings/variables useful in adjusting the I/O of search.php. main.css is the stylesheet containing presentation information. help.html is this file. Here, we'll focus on the the php and css files.There are three variables you MUST need to change in conf.php:
search.php is pretty straightforward. You can add elements (like directory, cache info, etc) to and adjust the look of the result output. Most of what you need, however, is in conf.php. main.css contains the font types and colors and table background color. Adjust the properties for individual styles to affect the look of your page. Add styles in this file and reference them with the class attribute in your HTML code.
Local InstallMany users have a shared provider that grants access to a system-wide PEAR installation. However, in many cases, it is advantageous to have a local copy of PEAR that can be used for packages that are not installed by the host provider. There are ways of installing PEAR both for users with a telnet/ssh shell access and users who only have ftp access.To install PEAR's manager through SSH, you can use this command sequence to set up a local copy of PEAR: $ pear -s -c ~/.pearrc -d doc_dir=~/pear/docs -d ext_dir=~/pear/ext \ -d php_dir=~/pear/lib -d data_dir=~/pear/data -d test_dir=~/pear/tests \ -d cache_dir=~/pear/cache -d bin_dir=~/pear/binThis will create a local configuration file in a file in your home directory named .pearrc. In addition, it will create a directory structure based on a subdirectory of your home directory named pear that contains all of the packages that you install. Then, if you add ~/pear/bin to your path as the first entry in .bashrc (or whatever your startup file is), and run the command: $ pear -c ~/.pearrc install Archive_Tar PEAR Console_Getopt XML_RPCYou will have a local version of PEAR that supersedes the system's copy. To use the files you have installed, you should set your PHP include_path in either the code that uses your PEAR packages like so: <?php ini_set('include_path', '~/pear/lib' . PATH_SEPARATOR . ini_get('include_path')); ?>Or, in an .htaccess file for apache using php_value.
Download
Andre S. Burton Last update: March 24, 2004
|