home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeManaging and Using MySQLSearch this book

11.2. Installing PHP

PHP works on almost all Unix platforms and with Microsoft Windows 32-bit environments. In Unix environments, PHP can be used to develop three different types of software:

Command-line scripts
PHP can be used as an alternative to Perl, Tcl, shell scripts, and other scripting languages.

GUI Windowing applications
With the PHP-GTK extension, PHP can be used to develop window-based applications.

Server-side scripts
PHP can be used to process scripts that are requested with a web browser

PHP was designed for the third alternative. To use it in this environment, a web server is required. We focus on integrating MySQL with the web environment in this chapter.

PHP can be used for web scripting by integrating it as a module of a supported web server such as Apache, Microsoft Internet Information Server (IIS), or iPlanet. For web servers that do not support module integration—those that do not support SAPI or ISAPI direct module interfacing—the PHP executable can be used as a CGI processor. The Common Gateway Interface (CGI) allows a web server to run any executable, but this is a much slower method of running the PHP engine than integrating it as a server module. In either case, to use PHP to access the MySQL DBMS, it must be compiled with MySQL support.

11.2.1. Getting Started Under Unix

Before installing PHP, you should check whether you already have a web server that supports PHP and whether your PHP engine supports MySQL. For example, many Linux distributions now include the Apache web server with preconfigured PHP support for accessing the MySQL DBMS.

The simplest way to check if your web server supports PHP, and if the PHP module supports MySQL, is to create a file phpinfo.php in the web server document root. Create this file so that it has only one line with the following contents:

<?php phpinfo(); ?>

For most systems that are running the Apache web server, the document root is the directory: /usr/local/apache/htdocs/.

After creating the file, run the script by requesting the following URL with a web browser that is running on the same machine as the web server: http://localhost/phpinfo.php.

If you see output—not the script contents—then your web server has PHP support. The Configure Command section near the top of the output will include the option --with-mysql if MySQL support is built-in; scrolling down through the output should also show a section headed mysql.

If this checks out, you're ready to start with PHP and MySQL. If not, then additional configuration is required. Suggested steps are included in this section.

Here are three possible ways to get started with a web server, PHP, and MySQL support:

11.2.1.1. Installation problems

If you have a MySQL installation that you're happy with, but don't have a web server and PHP, then the easiest approach is to install a web server and PHP package. The best choice is the Apache web server, because it's popular, free, and flexible in its integration with PHP. We focus on Apache in this section.

If you have an Apache web server that appears not to support PHP, it's worth double-checking. There are three common problems that can give the wrong impression:

If you have Apache and PHP, but not MySQL support, you need to find out whether your PHP module is a web server dynamic shared object (DSO). To check if your PHP is a DSO, take a look at the output of the phpinfo.php script you created in the previous section. If the Configure Command section contains the string --with-apache=, your PHP is not a DSO. If it contains the string --with-apxs=, your PHP is a DSO.

If your PHP module isn't a DSO, you need to rebuild your PHP and Apache to include MySQL support. This is the disadvantage of having a statically linked PHP module. The advantage of static linking is that the module is preloaded when the web server starts up, and a static-linked module is faster. Instructions for rebuilding a static-linked module version can be found at: http://www.php.net/manual/en/install.unix.php. As discussed earlier, ensure that you include the --with-mysql= directive in the PHP build process and that the directive includes the path to your MySQL installation.

If your PHP is a DSO, the upgrade process is simpler. This is the primary advantage of a DSO. You only need to rebuild the PHP module by rerunning the configure script with the addition of the --with-mysql= directive; again, make sure you include the path to MySQL with the --with-mysql= directive. Run make and make install to complete the process. You then need to restart your web server so that the new PHP module is loaded.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.