Download the latest version of PHP at http://windows.php.net.
Download the zip version with thread safe as shown below.
Once you've finished downloading the file, unzip it to wherever you want.
Create a new folder in "C:\Apache" name it "php" so the path to the folder is "C:\Apache\php"
Copy all files and folders you've unzipped over to "C:\Apache\php".
In the folder "C:\Apache\php" find and rename "php.ini-production" to "php.ini"
Double click the php.ini to open it and find the following line:
Add path to the Document Root, you can find it in your Apache configuration file:
doc_root = "D:\My Websites"
Find the next line:
; extension_dir = "ext"
Uncomment it and add path to the PHP extensions directory:
extension_dir = "C:\Apache\php\ext"
By default PHP uses Windows temp as temporary folder. Once, I got errors in a script while accidentally I emptied the system temp folder. So it's might be a good idea to create a separate temp folder for PHP.
Create a new folder in "C:\Apache" name it "temp" inside the "temp" folder create 2 folders name them "upload" and "session" Now we got 2 new folders, they are "C:\Apache\temp\upload" and "C:\Apache\temp\session"
In the PHP configuration file (php.ini) find the line below:
Uncomment it and add path to the upload folder we've just created:
And the next line:
;session.save_path = "/tmp"
Uncomment it and add path to the session folder:
Adding PHP to the System Path.
Open up System Properties, to open it right click My Computer and then click Properties, in the Control Panel Home menu click Advanced System Settings.
In the Advanced tab click on Environment Variables.
In the "System Variable" double click "Path" variable to edit it, add path "C:\Apache\php" into the Variable value, click OK to save the configuration.
The Computer must be restarted to take effect.
Connecting the Apache Server with PHP.
To connect the Apache Server with PHP we need to edit the Apache Configuration file located at C:\Apache\conf\httpd.conf
Find DirectoryIndex as follows:
<IfModule dir_module> DirectoryIndex index.html </IfModule>
Add index.php to the line
<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
Add the following lines between <IfModule mime_module> and </ IfModule>
ScriptAlias /php/ "C:/Apache/php/" AddType application/x-httpd-php .php .php5 Action application/x-httpd-php "/php/php-cgi.exe" SetEnv PHPRC "C:/Apache/php"
Add the following lines to the end of the httpd.conf
PHPIniDir "C:/Apache/php/" LoadModule php5_module "C:/Apache/php/php5apache2_2.dll"
Update February 2013
If you are using Apache v2.4, change the last line to load "php5apache2_4.dll" module.
LoadModule php5_module "C:/Apache/php/php5apache2_4.dll"
You can download php5apache2_4.dll module from http://www.apachelounge.com/download/additional/ in Modules section, after you've finished downloading the file, unzip it and place the file in PHP folder "C:\Apache\php\"
Make sure to download the right version with the PHP currently installed on your system, to check what your PHP version is, open up Command Prompt and type in "php -v" without quotation marks and press Enter.
*** Module php5apache2_4.dll included in PHP v5.4.10+ Binaries (no need to download anymore)
End of update
Restart Apache Server.
Open up Notepad, copy and paste the code below:
<?php phpinfo(); ?>
Save the file into Apache document root "D:\My Websites" as "phpinfo.php"
Open up browser, in the address bar type in "http://localhost/phpinfo.php" and then press Enter.
If you did it right, you should see something like the image above.
In the next chapter we will install MySQL.