Setting Up Your Own Web Server on a Windows Machine - Part II (PHP)
This tutorial will show you how to install and configure PHP under Windows XP. This tutorial requires you to have Apache HTTP server installed on your local machine. If you haven't done so, you can complete part one of this tutorial. We will use Apache version 2.2.4 and PHP 5.2.1 for this tutorial.
Downloading PHP
Same as Apache, we will use the latest version of PHP. As the time of writing, the latest version is 5.2.1. Download PHP 5.2.1 here.
You can also download a copy from PHP's official site. Just go to http://us3.php.net/downloads.php, and follow the link PHP 5.2.1 zip package, select a mirror which is closest to you. Note that we are using the zip version, not the one come with a installer.
Once you have downloaded the zip package, extract it to anywhere you want. The suggested location is C:\php.
Installing PHP as an Apache Module
It is time to configure Apache so it can serve PHP pages. We will configure PHP as an Apache module.
Open Apache's configuration file, [PATH_TO_APACHE]/conf/httpd.conf in a text editor. If you installed Apache to the default location, it can be found at C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf.
Add the following lines to the end of Apache's configuration file:
For Apache 2.2.4
# For PHP 5 do something like this:
LoadModule php5_module c:/php/php5apache2_2.dll
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir C:/php
For Apache 2.0
# For PHP 5 do something like this:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
That's it, you've just enabled PHP support on Apache.
Testing PHP Installation
To verify PHP is installed properly, create a php file under your Apache's document root, save it as info.php. By default, Apache's document root is located at [PATH_TO_APACHE]\htdocs.
Insert the following PHP code into info.php:
<?php
phpinfo();
?>
Visit http://localhost/info.php. If your PHP installation is working properly, you should see a page generated by phpinfo():
Configuring PHP
Similar to Apache, you can configure PHP by changing its configuration file. Navigate to the root of your PHP installation directory, you will find a file named php.ini-recommended. Make a copy of this file and rename it to php.ini. Open php.ini in a text editor.
Again, you will see a lot of options provided for you to fine-tune PHP. However, there are only a few configurations you may want to modify at this time.
Setting Error Reporting Level
Since we are setting up a test server, we want to see error messages generated by the PHP scripts during the execution time - it makes debug much easier.
If you want to see execution error messages in your browser, make sure you set error_reporting to E_ALL and display_errors to On:
error_reporting = E_ALL
display_errors = On
;show start up error
display_startup_errors = On
Turn display_startup_errors on is recommended because it enable you to track down startup errors easily.
Setting Extension Path
Make sure you set extension_dir to the correct path before you enable any extensions.
extension_dir = "C:\php\ext"
Enabling/Disabling an Extension
Remove the comma ";" in front of an extension to enable it; add a comma to the front to disable it.
Some extensions require extra libraries (DLL files under the PHP root directory) to run, for instance, extension php_mysql.dll requires libmysql.dll to run. Make sure those extra libraries are visible by Apache. Here are two ways to make Apache to recognize them:
- Add PHP's root directory to your system path
- Copy the required DLL files to Apache's bin folder
You can choose either way. Don't forget to restart your computer if you have used the first method.
Here's a list of extensions in the default php.ini:
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll
Next: Installing MySQL
More interesting posts ...
Leave a Comment
If you would like to make a comment, please fill out the form below.
If you want to post source code, please wrap it with <pre> and </pre>




Hi,
I am running Vista (Home Premium) on HP Pavilion (Core 2Duo E63000).
I have Apache2.2 working successfully (Apache Monitor confirms it).
I have done all configuration in php.ini, apache/../httpd.conf, windows/hosts etc.
When testing 'hello.html' in Flock browser under http://localhost:8080/hello.html
It would work and display
HELLO
So, that means that the Browser can work fine with the regular '.html' files.
But I have a problem with http://localhost:8080/
and
http://localhost:8080/index.php
Where 'index.php' is my PHP file with phpinfo(),
and the browser goes WHITE BLANK (that is showing nothing).
My server root directory is 'C:/htdocs', and here are the files index.php and hello.html.
Please advise any suggestions or comments that you might have.
Regards,
MV