The Server-Side Scripting Language: PHP – Installation and Configuration
PHP is a very capable server-side Web-oriented scripting language used on many Web sites. Its usage is growing as are its capabilities. It is browser independent, and cross-platform.
You can obtain the latest stable release of PHP at http://www.php.net/downloads.php. If you are interested in development versions of the next Windows release, go to http://snaps.php.net/win32/. If you are looking for past release builds for Windows go to http://ftp.proventum.net/pub/php/win32/. Online documentation for installation on Windows, with user comments, is available at http://www.php.net/manual/en/install.windows.php. The file install.txt
that comes with the distribution also explains PHP installation on Windows.
Another good source of installation information is the User Contributed Notes at the bottom of the online PHP documentation page for installing PHP on Apache: http://www.php.net/manual/en/install.apache.php. Documentation for offline use can be downloaded from http://www.php.net/download-docs.php. A good way to keep up with PHP developments is to read the PHP Weekly Summary at http://www.zend.com/zend/week/.
This tutorial, however, is about installing PHP as an Apache module. A module takes advantage of the Web server’s native Server API, or SAPI. PHP as a module runs faster than PHP as a stand-alone CGI script, but on Windows it has been said that SAPI support is not as stable — although I haven’t experienced any problems with my small-scale use of PHP as an Apache module on Windows.
To install PHP, extract the files and folders from the download, php-4.2.2-Win32.zip
. For the sake of this article, I will assume that these extracted files are contained in a top-level folder titled php
(rename the extracted folder php-4.2.2-Win32
to php
). Like the Apache folder, put it at the root of the C:
drive. Thus, the path to the folder is C:php
.
Then, copy the file php4ts.dll
from C:php
into C:WINNTsystem32
. Also, copy the mibs
folder from C:php
into C:usr
(you may need to create the usr
folder first).
The recommended configuration settings for PHP are given in the file php.ini-recommended
, which is located in the php
directory. To create the actual PHP configuration file that you will be using, you can copy php.ini-recommended
, edit it, and rename it to php.ini
. The php.ini
file must be located in the C:WINNT
directory.
The following are the significant changes that I made to php.ini
:
Changes to
|
Here are some comments on the changes noted above:
I turned off short_open_tag
so that I could serve XHTML files, which begin with something like:
I turned display_errors
to On
to help with development. For production sites, it is recommended for security reasons that this be set to Off
.
I created a directory C:tempsessions
to hold temporary session files.
For greater security, and for load balancing on larger sites, session data can be stored in a database rather than in files. This requires additional work, however, as the the custom session handling functions must be set up.
The following four references provide additional information (note that in the examples register_globals
are On
):
- Web Database Applications, Appendix D
- Programming PHP, Chapter 7
- Professional PHP4, Chapter 8
- Session Tracking: Part 2
For a basic explanation on using include
files see http://hotwired.lycos.com/webmonkey/99/21/index4a.html. I put my include
files (*.inc
) in C:phpinc
, outside of Apache’s htdocs
folder, for security reasons.
As can be seen from the configuration file, I created the directory C:php_log
to store my PHP error log, php_errors.log
.
I used a directive, session.cookie_secure = 1
that ensures session cookies are sent only when SSL connections are available. If you need to use cookies in a non-SSL (i.e., regular) browser session, do not use this directive.
|
By the way, I “experimented” with using the least number of files to run basic PHP and found out that it runs with just four files: C:phpphp.exe
, C:phpsapiphp4apache.dll
, C:WINNTphp.ini
, and C:WINNTsystem32php4ts.dll
.
Installing PHP on a Volume Other Than
|
Once you get PHP installed, you can test to see if it is running using one of the simple scripts, such as “Hello World,” or phpinfo()
, given in the PHP Introductory Tutorial at http://www.php.net/tut.php
Discuss this article in the ServerWatch discussion forum.