Team LiB
Previous Section Next Section

Installing MySQL and PHP Modules

After 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.


We start with Linux, where installing extensions sometimes can be painful, but does not have to be.


As 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:

  • MySQL-server-*.rpm The MySQL server

  • MySQL-Max-*.rpm The MySQL server in an optimized version for large applications

  • MySQL-bench-*.rpm Benchmarks and test suites

  • MySQL-client-*.rpm Client tools

  • MySQL-devel-*.rpm Libraries and header files needed to compile MySQL

  • MySQL-shared-*.rpm Dynamic client libraries

  • MySQL-embedded-*.rpm The embedded MySQL server

  • MySQL-shared-compat-*.rpm Dynamic client libraries, including the libraries for the old 3.23.x versions

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 Figure A.6 shows this tool.

Figure A.6. Configuring MySQL is easy using phpMyAdmin.

PDF Support

For 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:


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

First, you have to download some helper libraries:

Then, download PDFLib from, 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.


In 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 extension

If 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:

  • Configure PHP with --enable-dba=shared. This creates a .so file that you can load using dl() within a PHP script or in php.ini.

  • Enable support for one or more specific DBA handlers. Chapter 27 lists all available handlers and configuration switches.

GD extension

In 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 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:

  • --enable-gd-native-ttf for native TrueType support

  • --with-freetype-dir=/path/to/freetype for FreeType 2.x support

  • --with-jpeg-dir=/path/to/jpeg for jpeg-6b support

  • --with-png-dir=/path/to/png for PNG support

  • --with-t1lib=/path/to/t1lib for Type 1 fonts support

  • --with-ttf=/path/to/ttf for FreeType 1.x support

  • --with-xpm-dir=/path/to/xpm for xpm support


For most other extensions, installation is and will be very similar; most of the time --enable-extensionname or --enable-extensionname=/path/to/extensionlibrary does the trick. For instance, the Direct IO extensions (that is unfortunately only available for Unix/Linux systems) can be installed using --enable-dio.

Some built-in extensions can also be deactivated using --disable-extensionname. For instance, the POSIX functions (again, only available under Unix/Linux) are automatically thereunless you use --disable-posix when configuring PHP.

Data encryption

The main library for data encryption in PHP is the mcrypt library, available at 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 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.


On the Microsoft platform, the installations are rather simple to do, or the modules are available as precompiled binaries.


For Windows, a GUI-based installer exists for MySQL, available at, 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 ( 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:


Also, PHP needs read privileges for the PHP installation directory because it contains the required MySQL client libraries.

PDF Support

When 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:


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.


The directory that PHP searches for extension DLLs is the one you provide in the php.ini configuration variable extension_dir.


One more caution when you are using the module version of PHP under Windows: Some extensions require additional DLLs. For instance, the extension for Microsoft's SQL Server needs the MSSQL client libs. These DLLs have to be copied to the Windows system directory for the extension to work; otherwise, you get a Cannot Load Extension error message.

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 encryption

In the mcrypt library, available at, 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

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:


    Team LiB
    Previous Section Next Section