Installing MySQL and PHP ModulesAfter PHP is up and running, additional modules might come in handy. This section briefly covers the installation of both MySQL and some PHP extensions. The descriptions are genuine enough to be able to be transferred to other extensions, as well. Besides that, the PHP online manual is available 24 hours a day for additional information. LinuxWe start with Linux, where installing extensions sometimes can be painful, but does not have to be. MySQLAs with PHP itself, MySQL comes with most distributions, so a few mouse clicks should do the trick. However, it is also possible to install the database manually. The MySQL website offers various RPMs to choose from:
For our purposes, the server, developer, client, and shared packages must be downloaded. The following command installs all packages: $ rpm -i MySQL*.rpm Afterward, start MySQL using mysqld and then administer it, for instance, using the PHP-based Web configuration tool phpMyAdmin, available at http://www.phpmyadmin.net/. Figure A.6 shows this tool. Figure A.6. Configuring MySQL is easy using phpMyAdmin.![]() PDF SupportFor installing the various extensions of PHP, you can use two approaches. Either create or download a static library (extension .so) and dynamically load it in your scripts: <?php dl("extension.so"); ?> For better performance, however, link the library to PHP. For example, we show how to install the PDF support that is used in Chapter 29, "Working with PDF Files." In this chapter, the external extension PDFLib is used; the associated manual page is http://www.php.net/manual/en/ref.pdf.php. First, you have to download some helper libraries:
Then, download PDFLib from http://www.pdflib.com/products/pdflib/, but have a look at the EULA (commercial use requires a license). Then extract the downloaded archive: $ gunzip -c pdflib-x.y.z.tar.gz | tar xvf Change to the newly created directory and configure the library. Provide the path you want PDFLib to be installed to: $ ./configure --prefix=/usr/local/pdflib $ make && make install Furthermore, you have to compile PHP with --with-pdflib=/path/to/pdflib (and --with-jpeg-dir=/path/to/jpeg and --with-tiff-dir=/path/to/tiff, if you have installed these libraries). Version 3 of PDFLib additionally requires the configuration parameter --enable-shared-pdflib. After that, the PDF extension is ready. Restart your Web server and run phpinfo() to see the results: a PDF entry in this function's output (see Figure A.7). Figure A.7. The PDF library has been successfully loaded.![]() XMLIn terms of XML, PHP 5 is much better than its predecessor. This of course means, that XML support is already built-in into the language. New (and still experimental) is a brand-new XSL extension. It is available by default, as well, however has to be enabled using the configuration switch --with-xsl=/path/to/libxslt. You need at least version 1.0.18 of the libxslt extension. DBA extensionIf you can't afford a "real" database (or your provider does not cooperate) and you do not want to use SQlite (which is enabled with PHP 5 by default and requires no installation), the DBA extension may be something for you. In order to use them, you have two options:
GD extensionIn order to dynamically create graphics in PHP, the GD library is the de-facto standard used for this task. Since PHP 4.3, the GD library (originally available at http://www.boutell.com/gd/) is bundled with PHP in a specially patched version. Therefore, installation is a snap: just use the configuration switch --with-gd. In the meantime, the GD library supports GIF again because the LZW patent expired. Furthermore, the GD extension can support more formats by using one (or more) of those configuration switches:
Data encryptionThe main library for data encryption in PHP is the mcrypt library, available at http://mcrypt.sf.net/. Download the source code configure it (including the option --disable-posix-threads) and compile it. Then, you can reconfigure PHP with the switch --with-mcrypt=/path/to/mcrypt to enable the mcrypt support. Another important library is the OpenSSL library, available at http://openssl.org/. Be aware that recently some serious security issues were found with older versions of the library, so do install the latest version available (PHP requires version 0.9.6 or higher). After installing the OpenSSL library, configure and recompile PHP with --with-openssl=/path/to/openssl. WindowsOn the Microsoft platform, the installations are rather simple to do, or the modules are available as precompiled binaries. MySQLFor Windows, a GUI-based installer exists for MySQL, available at http://www.mysql.com/, so you can click your way through it. After that, the database can be installed as a system service or started manually; for a production Web service, the former is recommended. To administer the database, you might as well use phpMyAdmin; however under Windows, some Windows GUIs exist. One of the best-known ones is SQLyog, which is not free; however, it is well worth its price (http://www.webyog.com/). You can see the tool in Figure A.8. Figure A.8. SQLyog: An easy way to work with MySQL data sources.![]() In order to activate the MySQL support of PHP, you have to load the required extension: either mysql for older versions of MySQL, or mysqli for MySQL 4.1x: extension=php_mysql.dll extension=php_mysqli.dll Also, PHP needs read privileges for the PHP installation directory because it contains the required MySQL client libraries. PDF SupportWhen you have a look at the extensions subfolder or the PHP installation directory, you will notice a file php_pdf.dll. That's a compiled version of PDFLib. Integrating it is easy, and the same goes for most of the other PHP libraries: Just remove the semicolon in front of the PDF line in php.ini so that it looks like this: extension=php_pdf.dll This loads the extension when PHP is restarted. If you are using PHP as a CGI module, PHP is restarted whenever you execute a new script. When you are using the module version, you have to restart the Web server.
All other extensions are installed the same way because they come already precompiled for Windows. For the sake of performance, it is probably better to load them using extension=php_extensionname.dll in your php.ini configuration file. Support for data encryptionIn the mcrypt library, available at http://mcrypt.sf.net/, many encryption algorithms like DES and Blowfish are implemented. PHP supports mycrypt functions as well, however you need both php_mcrypt.dll from the download archive and the mcrypt binaries available at ftp://ftp.emini.dk/pub/php/win32/mcrypt/. Another method for encrypting data over the web is by using SSL. This is implemented with the OpenSSL functions in PHP. Windows users need the libeay32.dll file in the PHP directory. Usually, the PHP interpreter searches for this file in the PHP folder, but of course read access is required. To be on the safe side, copy the file into a directory that is in the system PATH, like C:\WINDOWS\SYSTEM32. You also have to load the file php_openssl.dll in php.ini: extension=php_openssl.dll |