Using the Windows Installer for PHP 5.2.x
PHP 5.2.0 saw the launch of a vastly improved installer for Windows. Unlike earlier versions, the new installer automates the installation of a fully featured version of PHP on a wide variety of web servers, including the Apache 1.3, 2.0, and 2.2 series, as well as IIS.
These instructions assume that you have already installed a web server on your local computer. They have been tested on Apache 2.2 and IIS 5.1, but they should be easily adaptable to other web servers. Before testing these instructions, I removed my existing PHP setup completely, including all Windows environment variables, such as PHPRC and the the reference to the PHP folder in the Windows PATH. They are therefore suitable for a brand new installation of PHP, but may not work if you have an existing installation that you want to upgrade.
The new Windows package will not work on Windows 98 unless you have obtained an MSI installer from Microsoft.
In Windows Vista, you must disable User Access Control (UAC) temporarily while installing both Apache and PHP—see instructions here.
Go to the PHP downloads page at http://www.php.net/downloads.php and select the PHP 5.2.x Installer from the Window Binaries section. Note that the download is nearly 19MB (twice the size of the equivalent zip package). Download
php-5.2.x-win32-installer.msifrom a mirror site and save the file to your hard disk.
Close all Windows programs and double-click the
php-5.2.x-win32-installer.msifile to launch the installation wizard. You should eventually be greeted by the following screen. Click Next to start the installation.
The first dialog box displays the PHP Licence Agreement. You need to select the accept checkbox before the Next button can be clicked.
The wizard now gives you the option to choose where PHP should be installed. The default is
C:\Program Files\PHP\. Unless you have a strong reason for choosing another location, accept the default and click Next.
You now get the chance to select the web server that you want to use in conjunction with PHP. As you can see from the screenshot, there's a wide selection. I chose to install PHP as an Apache 2.2.x Module.
If you are using IIS, select IIS CGI. (The screenshot above was taken from the PHP 5.2.0 installer. In PHP 5.2.1, the IIS options have been renamed.) Although running PHP as an ISAPI module is preferable, the IIS ISAPI module option isn't currently enabled in the installer. Make your selection and click Next.
If you chose IIS in the preceding step, skip to step 7.
If you chose Apache, the wizard asks you to specify where the configuration file is located. In the case of Apache 2.2.x, it's
C:\Program Files\Apache Software Foundation\Apache2.2\conf\, as shown in the following screenshot.
Browse to the appropriate folder, click OK to return to the installation wizard, and then click Next.
The next dialog box lets you select which PHP extensions will be enabled. PHP offers a huge range of non-core extensions, so it's best to choose only those that you know you'll need. Click inside the dialog box to expand the Extensions tree menu. As an absolute minimum, you should select GD2, Multi-Byte String, MySQL, and MySQLi. Click the down arrow next to the extension name and select "Will be installed on local hard drive", as shown in the screenshot. The red X is replaced by a hard drive icon, indicating that the extension will be enabled.
If you are using The Essential Guide to Dreamweaver CS3 or Foundation PHP for Dreamweaver 8, you should also select XSL. For PHP Solutions, expand PDO and select MySQL (this is in addition to MySQL and MySQLi in the main extension list).
If you plan to do a lot of PHP development, you might also want to enable the Extras, which install PEAR and the PHP documentation on your local hard disk. If in doubt, don't bother. You need to have a solid understanding of PHP to use PEAR, and the online documentation is frequently updated, so having a local version is only of value if you need to work offline a lot.
Click Next when you have made your choices.
The wizard is now ready to install PHP. If you selected Apache, it asks whether you want it to configure Apache. Click Yes. After the installation, you should see two alert boxes telling you that the Apache configuration and mime.types files were successfully updated. Click OK and then click Finish to close the wizard. If you selected IIS, there are no other dialog boxes. Just click Finish when the installation is complete.
For all the changes to take effect, you must now reboot your computer. Among other things, this is necessary to add the PHP folder to your Windows PATH.
If you run
<?php phpinfo(); ?>, you should see that
php.inihas been placed in
C:\Program Files\PHP\php.ini. (In PHP 5.2.3 and above, the location of
php.iniis displayed as
Loaded Configuration File.)
Important differences in php.ini
The new Windows installer bases
php.ini-recommended, which imposes stricter standards than
php.ini-dist, the version normally recommended for a development environment. This is generally to be welcomed, because it forces you to create scripts that are more secure. However, you need to be aware of the following differences:
The wizard turns off the display of error messages and writes them instead to a log file.
For development purposes, I suggest that you change the settings in
display_errors = On
log_errors = Off
Magic quotes are turned off. Although many scripts rely on the use of magic quotes (the automatic insertion of backslashes in front of single and double quotes), I don't recommend turning them back on, because this feature will be removed permanently from PHP 6. All scripts created by Dreamweaver and in my books are designed to work correctly regardless of the setting.
Short open tags are turned off. This means that you must use the full opening PHP tag (
<?php). Since this is the recommended practice, you should leave the setting unchanged. Dreamweaver and the scripts in my books always use the full tag anyway.
Enabling sessions and uploads
The Windows installer designates
C:\Documents and Settings\<username>\Local Settings\Temp\php\upload as the value for
C:\Documents and Settings\<username>\Local Settings\Temp\php\session as
session.save_path. However, the installer doesn't create the necessary folders. Consequently, file uploads and sessions won't work until the folders are created. (In Windows Vista, the folders are
php.ini and rename the current folders to
C:\WINDOWS\Temp, or create the necessary folders in
C:\Documents and Settings\<username>\Local Settings\Temp (or the Vista equivalent). If you choose the option of renaming the folders, make sure you change the right settings in
php.ini. The installer leaves the original commands unchanged and inserts new ones. The original commands have a semicolon at the beginning of the line, so are ignored.
Remember to restart your web server after making any changes to
What the PHP installation wizard doesn't do
Although the new Windows installer considerably simplifies setting up PHP on Windows, it doesn't change the default location of
DocumentRoot on Apache, nor does it add
index.php to the
DirectoryIndex command. You still need to make those changes manually to
httpd.conf. For instructions on how to do this, see the following: