PHP3 Configuration on Apache Server for Windows NT

Summary

    1. Summary
    2. PHP Installation
    3. PHP configuration
      1. [PHP_3]
      2. [mail function]
      3. [LoadExtensions]
    4. Apache Configuration
    5. Tests
      1. Local test
      2. Remote test
    6. Common problems
        1. You get a Internal Server Error ( HTTP 500 )
        2. The browser displays the source code page instead of the parsed page
        3. The browser popups a "Unknown File Type / Save File" window
        4. You get a Bad Request Error ( HTTP 400 )
        5. You get a HTTP 400 Error
        6. "Fatal error: Unable to load dynamic library 'xxx.dll' "
        7. A window popups reporting that a DLL couldn't be found in the PATH
    7. Sources

PHP Installation

Install php-3_ORCx-win32.exe, following the installation directives. The installation shoud create a C:\php directory.

Copy the files php.exe, *.dll from this directory to [SERVER_ROOT]/cgi-bin/

Note:[SERVER_ROOT] is intended for the apache root directory, commonly C:\Apache

PHP configuration

Edit the php3.ini file located in the WinNT/ directory.

Some changes are to be done in the following sections.

[PHP_3]

This section contains the main PHP configuration directives.

It can be usefull -at least during the installation process- to keep a trace of errors in a log file:

log_errors=1 ; Log errors into a log file (server-specific log, stderr, or error_log (below)) track_errors=0 ; Store the last error/warning message in $php_errormsg (boolean) error_log=c:\Apache\logs\php3.log ; log errors to specified file

You must check the cgi_ext directive, which defines the extension your php files will have. We'll use php3 here.

; file extensions (meaningless in UNIX) cgi_ext=php3

Note:The PHP files extension (php3 here ) must be the same you will configure for Apache: isapi_ext is used for a IIS server. nsapi_ext is used for a Netscape Server

If you plan to use upload files fonctionnality, define the directory where php will store the temporary uploaded files.

upload_tmp_dir=c:\temp ; temporary directory for HTTP uploaded files

[mail function]

If you plan to use the mail() function, change:

SMTP=[your mail server, for ex. mail.myprovider.net] sendmail_from=[the server admin e-mail address]

[LoadExtensions]

This section defines which DLL should be loaded. The .DLL files are located in [SERVER_ROOT\cgi-bin] since you copied them in A For example, if you plan to use GD ( Graphic functions library ), add:

extension=gd.dll

Apache Configuration

We assume that : Apache server is located in the usual ``c:\Apache'' directory. PHP scripts have .php3 extension

Edit the Apache access.conf config file, located in SERVER_ROOT/conf/ . ( httpd.conf if Apache version 1.3.5 or up )

Check the the cgi-bin directory config. It must have the ExecCGI directive :

<Directory "C:/Apache/cgi-bin"> AllowOverride None Options ExecCGI </Directory>

Edit the Apache srm.conf config file, located in SERVER_ROOT/conf/<br>

Check for or add the directive that will declare your cgi-bin directory:

ScriptAlias /cgi-bin/ "C:/Apache/cgi-bin/"

Add the directive to declare the MIME-Type for the PHP3 files. The format is AddType [mime-type] [file extension]

AddType application/x-httpd-php3 .php3

Add the directive that will bind the php.exe program with the php mime-type.

Action application/x-httpd-php3 "/cgi-bin/php.exe"

The previous directives will allow simplified urls , ie. http://server/directory/my_script.php3 instead of http://server/cgi-bin/php.exe/directory/my_script.php3

Save the configs files, and restart Apache using the NT Services utilities found in the Control Panel.

Tests

Create a simple test.php3 file, and save it somewhere under [SERVER_ROOT]/htdocs directory.

<? echo "Hello, world\n"; ?>

Local test

The purpose of this test is to isolate any PHP specific problem. Open a DOS Shell in the directory where test.php3 is, and try the script:

C:\[PATH]>c:\apache\cgi-bin\php.exe test.php3 Content-type: text/html Hello, world

If you don't get this, check PHP3.INI. Only when done, you may try the remote test.

Remote test

Open a browser, point it to the URL of your script, in our example : http://localhost/test.php3

If you get no response, have a look in the Apache error_log file. Also check the PHP log file ( should be [SERVER_ROOT]/logs/php3.log ) . They might give you some hints

Common problems

Here are some common configuration problems and solutions.

Please note that each time you make a change in Apache conf files (httpd.conf, srm.conf, access.conf) , you have to restart Apache service after

You get a Internal Server Error ( HTTP 500 )

A possible reasons is that the php3.ini file is missing in WinNT/ directory.

-> Copy Apache/cgi-bin/php3.ini-dist to WinNT/php3.ini, and configure it. [ PHP configuration ]

The browser displays the source code page instead of the parsed page

-> Check that you have the AddType and Action directives correctly defined in Apache config file

AddType application/x-httpd-php3 .php3 Action application/x-httpd-php3 "/cgi-bin/php.exe"

The browser popups a "Unknown File Type / Save File" window

This means Apache doesn't recognize properly the PHP3 mime-type.

-> Check that you have the same mime-type (application/x-httpd-php3) in AddType and Action directives:

AddType application/x-httpd-php3 .php3 Action application/x-httpd-php3 "/cgi-bin/php.exe"

You get a Bad Request Error ( HTTP 400 )

This happens when the Action directive contains a syntax error in path.<br>

-> Check that the Action directive is correct, see Apache Configuration

You get a HTTP 400 Error

( [warn] handler ``php3-script'' not found for: [php file] )

This warning in Apache/log/error_log, is often not an error. It appears also when the AddHandler directive is defined. It seems to be a cosmetic bug in Apache.

"Fatal error: Unable to load dynamic library 'xxx.dll' "

You may have not defined the path where php looks for library files.

-> Check the extension_dir directive in php3.ini

Example: extension_dir=c:\Apache\cgi-bin

-> Also notes that since PHP version 3.03, library files have been renamed with a leading php_. ( ie gd.dll becomes php3_gd.dll ). You may have this error with existing php scripts when upgrading.

A window popups reporting that a DLL couldn't be found in the PATH

( This problem was reported when using libmysql.dll. )

-> Move the missing library to a library directory, for instance under [WIN]\System32.

Sources

Apache Configuration

http://www.apache.org/docs/

PHP3

http://www.php.net/FAQ.php

http://www.php.net/manual/

This document written by Leo West - 1998/99

You can send me any questions about Apache or PHP3 configuration on WinNT @ mailto:lwest@free.fr