Installing PHP for Windows doesn't occur through a wizard interface. Basically, you just unzip some files and move them around. No big deal. Just follow along very closely, because this is the area where most people miss an instruction, and if you do that, it won't work.
| Note |
Okay, so there is a Windows installer for PHP, if you're going to use PHP with Microsoft IIS, Microsoft PWS, or the Xitami web server. This book is based on a recommendation of using Apache as the web server, and to perform the manual installation of PHP. If you choose to install PHP with a different web server or are using a different method, please read the installation instructions contained within the software you choose. |
To download the PHP binary distribution for Windows, visit the Downloads page at the PHP website: http://www.php.net/downloads.php.
From the Windows binaries section, follow the link for PHP 5.x.x zip package, where x.x refers to the version. Currently, the version for Windows is 5.0.0RC1, and all subsequent installation instructions will be based on this version. Future versions will follow the same installation procedure; substitute the new version name as appropriate.
Once downloaded to your system, double-click on the file called php-5.0.0RC1-Win32.zip. Your zipping program of choice, such as WinZip or PKZip, will open this file.
Extract the files to the top level of your hard drive, into a directory called php.
You now have all the basic PHP distribution files; you just need to move a few of them around.
| Note |
If you change the installation directory name, be sure to substitute your new directory name in the remaining instructions in this chapter. |
Using Windows Explorer (or whatever method you prefer for moving through your file system), go to the C:\php directory.
Rename the php.ini-dist file to php.ini and move this file to C:\WINDOWS\, or C:\WINNT\, or wherever you usually put your *.ini files.
Move php5ts.dll to C:\WINDOWS\SYSTEM\, or C:\WINDOWS\SYSTEM\, or wherever you usually put your *.dll files.
To get a basic version of PHP working with Apache, you'll need to make a few minor modifications to the Apache configuration file.
You can install PHP as a CGI binary or as an Apache module. The current recommendation by the PHP Group (and me) is to use the module version, because it offers greater performance and some additional functionality. However, you might encounter some conflicts with advanced functionality when using the module, depending on your particular operating system. Additionally, using the CGI version instead of the module version will allow you to create virtual hosts, each with its own PHP CGI executable, therefore allowing PHP to run as a named user instead of the default Apache process owner.
If you would like to install the CGI version, please read the installation information in the PHP manual at http://www.php.net/manual/. In the next section, you learn to install the module version of PHP for the Apache 2 server.
To configure Apache to use the module version, you have to move one piece of PHP and also make a few modifications to the Apache configuration file, the httpd.conf file, located in the conf directory within the Apache installation directory.
Choose Program Files, Apache HTTP Server 2.0.49, Configure Apache Server, Edit the Apache httpd.conf Configuration File from the Windows Start menu
Look for a section of text like the one shown in the figure.
Add the following code to the end of that section:
LoadModule php5_module c:/php// php5apache2.dll
Next, you have to add a directive to the httpd.conf file to define the file extensions used by PHP files. Common extensions are .php and .phtml, but you can use whatever you want.
Look for a section of text like the one shown in the figure.
Add the following line:
AddType application/x- httpd-php .phtml .php
Save and close the httpd.conf file.
This final modification tells Apache that any time a file with an extension of .php or .phtml is requested, Apache should utilize the module version of the PHP parser before sending any output to the web browser.
Now that all of your modifications have been made to the httpd.conf file—no matter the configuration method—you can restart Apache using the method you learned in Chapter 2, "Installing Apache." To test that Apache and PHP are playing nice together, you'll next create a simple PHP script to test your installation. PHP scripts and other files (HTML, images, and so on) should be placed in the document root of your web server. For Apache, the document root is the htdocs directory within your Apache installation directory.
Open a new file in your text editor and type the following:
<? phpinfo(); ?>
Save the file with the name phpinfo.php and place this file in the document root of your web server.
| Note |
Be absolutely sure your file extension is .php or .phtml (or another extension you configured for PHP). It is very common for Windows-based text editors to add a hidden file extension of .txt to the end of the filename. If that happens to you, your script will not parse as PHP, only text. So keep an eye on your extension! |
Open your web browser and type http://127.0.0.1/phpinfo.php.
| Note |
If you used a different server name when you installed Apache, substitute it here and throughout the book. |
The output of the phpinfo.php script should be a long page full of system and environment information. This information is very helpful when you're trying to figure out what's available to you. If you browse through the results, you'll see that the following extensions are preinstalled (along with many others):
Perl-compatible regular expression support
ODBC support
Session support
XML support
MySQL support
Having these items preinstalled means that no additional .dll files are necessary for these functions to be available to you. For more information on obtaining .dll files for additional PHP functionality, see Appendix A, "Additional Configuration Options."
You're now ready to move on to Part II, "The Absolute Basics of Coding in PHP," and learn the fundamentals of the PHP language.