15.1 Installing and Configuring PHP on Windows


This section shows you how to install PHP on Windows. We cover both manually configuring your web server to use PHP, and the use of the PHP installer, which will do the configuration for you.

15.1.1 Going Straight to the Source

The most recent version of PHP can always be found at http://www.php.net/downloads.php. While you could download the source and compile it yourself, chances are you don't have a compiler. Fortunately, the PHP downloads page has a binary distribution for Windows.

Download the latest Windows PHP distribution and extract it into a local directory. You'll need a program such as WinZip (http://www.winzip.com) to extract the ZIP file. At the root level of the distribution is php.exe, which you can run from a command prompt to test and experiment with PHP. If you have PHP code in a file (e.g., test.php), you can run that code with:

C:\> php -q test.php

15.1.2 Configuring PHP with a Web Server

Once you have PHP on your local computer, the next thing to do is to configure it into a web server.

The choices here are many. PHP can either be run as a standalone CGI script or linked directly into the server via the server's native Server API (SAPI). There's SAPI support for IIS, Apache, Netscape iPlanet, and AOLserver. PHP can even be configured to run as a Java servlet engine.

Because of the rapid change in the development of PHP, it is always best to check with mail lists and online resources to determine the best configuration for your specific application. In general, the CGI version is more reliable, but it is slower than SAPI implementations because it has to be loaded with each request. SAPI implementations load once and create a new thread for each request. Although this is more efficient, the tight coupling with the server can bring the entire server down if there are memory leaks or other bugs with an extension. SAPI support on Windows is considered to be unstable as of the writing of this book, and hence is not recommended for production environments.

For our discussion, we will look at and compare installation on Microsoft Personal Web Server (PWS) and Apache for Windows, both on Windows 98 two installations that help to contrast the differences in implementation while providing useful local development environments.

15.1.2.1 Configuration common to all Microsoft installations

Regardless of the server you use, there are a few steps common to all installations in a Microsoft environment:

  1. Decide where to extract the distribution. A common location is c:\php.

  2. Copy the php.ini.dist file to c:\windows\php.ini, or specify the location in the PHPRC environment variable. Edit the file to set configuration options.

  3. Ensure that the system can find php4ts.dll and msvcrt.dll. The default installation has them in the same directory as php.exe, which works. If you want all your system DLLs together, copy the files to C:\WINDOWS\SYSTEM. Alternatively, add the directory containing the PHP DLLs to the PATH environment variable.

DLL search order varies slightly between versions of Windows. In most cases, it is as follows:

  1. The directory from which the application loaded

  2. The current directory

  3. Windows 95/98/Me: the Windows system directory; Windows NT/2000 or later: the 32-bit Windows system directory (SYSTEM32)

  4. Windows NT/2000 or later: the 16-bit Windows system directory (SYSTEM)

  5. The Windows directory (WINDOWS)

  6. The directories listed in the PATH environment variable

15.1.2.2 Using the PHP installer to automatically configure PHP

The PHP development group offers an installer that configures a Windows web server to work with PHP. This is the recommended method of installation, as you don't need to learn how to edit the registry or how to configure Apache. It is available for download from http://www.php.net/downloads.php. PHP's installer will automatically configure your server for many of the more popular web servers for the Microsoft platform, as shown in Figure 15-1.

Figure 15-1. Choosing the server type in PHP's installer
figs/pphp_1501.gif

After you install your preferred web server, running the installer will prompt you for some values for typical php.ini configuration and the desired web server and configuration to use. Modifiable parameters here include the install path for PHP (typically c:\php), the temporary upload directory (the default is c:\PHP\uploadtemp), the directory for storing session data (the default is C:\PHP\sessiondata), the local mail server, the local mail address, and the error warning level.

15.1.2.3 Manually configuring PWS

To configure PHP for Personal Web Server, you must add a line in the registry that associates .php files with the PHP engine. For Windows 98, that line is:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map] ".php"="C:\\PHP\\php.exe"  

You must also enable execution of scripts in each directory in which you want to run PHP. The exact method of doing this varies between versions of PWS it may be an option when you right-click on the directory from the Explorer or a Control Panel option, or it may be done through a separate PWS configuration program.

15.1.2.4 Manually configuring Apache

Apache uses a single configuration file, httpd.conf, rather than the system registry. This makes it a little easier to make changes and switch between CGI and SAPI module configurations.

Add this to httpd.conf to configure PHP as a SAPI module:

LoadModule php4_module c:/php/sapi/php4apache.dll AddType application/x-httpd-php .php

To execute PHP scripts via CGI, add the following to the httpd.conf file:

AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php.exe"
15.1.2.5 Other installers and prepackaged distributions

There are also a variety of prepackaged Windows distributions of PHP available on the Web. These distributions can make it easier to get a web server and PHP running, and some offer more features or a smaller footprint. Table 15-1 shows some of the more interesting distributions available at the time of writing.

Table 15-1. Prepackaged distributions of PHP-related tools for Windows

Product

URL

Description

PHPTriad

http://www.PHPGeek.com

Apache, PHP, and MySQL in a standard CGI distribution for Windows. Convenient for those who want to get up and running quickly and who don't care about where things are located.

Merlin Server

http://www.abriasoft.com

A complete web development and production server that includes a secure, SSL-supported release of Apache, MySQL, and PostgreSQL, plus development languages such as PHP and PERL. It also includes a complete open source e-commerce software platform and comes with a template-based web portal and news system.

15.1.3 Adding Extensions to the Base Distribution

PHP on Windows has out-of-the-box support for ODBC and MySQL. Most other extensions must be manually configured (i.e., you must tell PHP where to find the DLL files).

First tell PHP which directory contains the extensions by adding this to your php.ini file:

extension_dir = C:\php\extensions; path to directory containing php_xxx.dll

Then explicitly load the module with a line like this in the php.ini file:

extension=php_gd.dll; Add support for Tom Boutell's gd graphics library

You can determine what extensions are available for your particular version by looking in the extensions directory of your distribution.

Once you have made these changes, restart your server and check the output of phpinfo( ) to confirm that the extension has been loaded.



Programming PHP
Programming PHP
ISBN: 1565926102
EAN: 2147483647
Year: 2007
Pages: 168

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net