Install the PHP Engine on Your Windows PC

If you want to write your own PHP scripts, you'll need to install the PHP engine first. It's relatively easy, and this article will show you how to do so.

Steps

  1. If you haven’t done so already, download the PHP Windows Binaries - You can download the software from the PHP.net website, (http://www.php.net/downloads.php) Be sure to download PHP 5.2.9 installer Windows installer and PHP 5.2.9 zip package. (Note: the version numbers might be different). Save the files on your Windows Desktop.
  2. On your Windows Desktop, double click the PHP installer file. Once you've done that, you should see a window that looks like this:

  3. Click "Next>".
  4. On the next window, click "I Agree".
  5. On the next window, click the radio button "Advanced", and click "Next>".
  6. We're going to install PHP in our server directory instead of the default PHP directory, so in the "Destination Folder" group, click "Browse".
  7. A browser window will open. Change the destination directory to "C:\Server\PHP". There is no need for a trailing backslash.
  8. Click "OK" on the browser window, and then click "Next>".
  9. Select "Next>" on the next three screens.
  10. On the following window, leave the SMTP defaults as they are, and click "Next>".
  11. If you want, you can enter an email address. This will be used as the "From:" email address when using PHP's mail function.
  12. On the next window, make sure that the radio button "Display all errors warnings and notices" is clicked. Then click "Next>".
  13. On the next window is where you pick which web server software you are using. Since you have installed Apache, pick "Apache" from the list. Then click "Next>".
  14. On the next window make sure that the check box ".php" is checked, and then click "Next>".
  15. Now that you have set all the options, you should see a window that looks like this:

    PHP is ready to install, so click "Next>" to begin the installation.
  16. If a message window pops up asking, "Do you want to keep your php.ini file", click "NO".
  17. Wait for a message window to pop up, that looks like this:

    • This is normal. Click "OK". When the PHP installer window pops up, click "OK" again.
  18. Now PHP is installed, but we need to change some of Apache's settings to get everything working the way it should.
  19. In Windows, open "My Computer", and browse your way to the folder "C:\Server\Apache2\conf".
  20. Double click the file "httpd.conf" so we can edit it. This will normally open the file in Notepad, unless you use a different program.
  21. Scroll to the very bottom of the page, and add these lines:
    • ScriptAlias /php "c:/server/php/"
    • AddType application/x-httpd-php .php
    • Action application/x-httpd-php "/php/php-cgi.exe"
  22. Highlight and copy the text from this page, and then paste it into the httpd.conf page to ensure there are no typos. Hit "Enter" after the last line to ensure there is one blank line at the end of the file.
  23. Move the file "C:\Windows\php.ini" to the directory "C:\Server\php" so it’s easier to edit when you need to.
  24. Open "My Computer" and browse to "C:\Windows".
  25. Find the file "php.ini" in the windows directory.
  26. Right-click the file and pick "Cut".
  27. Browse to the directory "C:\Server\php".
  28. Right-click an empty area in the window and select "Paste". This moves the "php.ini" file from the Windows directory to the PHP directory.
  29. Double click the file php-5.2.9-win32.zip that is saved on your desktop. (Note: the version number might be different).
  30. Extract the contents of this file to "C:\Server\php"
  31. Using Notepad, open the file "C:\Server\php\php.ini".
  32. Find that line that reads: extension_dir = "./" (or something similar, as long as its the line with "extension_dir".
  33. Change the line to: extension_dir = "C:\Server\php\ext"
  34. Find the line that reads: ;extension=php_mysql.dll Delete the ; so that the line now reads: extension=php_mysql.dll
  35. Open the directory "C:\Server\MySQL\bin".
  36. Find the file "libmysql.dll".
  37. Right-click the file and select "Copy".
  38. Browse to the directory "C:\Windows\System32" and Paste the file into that directory.
  39. Restart Apache to ensure the new lines added to the httpd.conf file have an effect.
  40. On the Windows taskbar click "Start">"All Programs">"Apache HTTP Server">"Control Apache Server">"Restart". This should restart the Apache server. Now we need to create a test PHP to see if everything is working.
  41. Open Notepad (usually found in "Start">"All Programs">"Accessories">"Notepad"), and copy and paste the following lines into a new document: <?php phpinfo(); ?>
  42. In Notepad, click "File">"Save". Save this file in the directory "C:\Server\Apache2\htdocs" as "phpinfo.php". Notepad has a bad habit of adding .txt to the end of all documents you save, so make sure from the "Save" dialog that comes up in Notepad, change "Save as type" from "Text Documents (*.txt)" to "All Files". Now click the "Save" button to save your new PHP document.
  43. Open your favorite browser. In the address bar, type "http://localhost/phpinfo.php". If everything is set up correctly, you should see a page that looks like this:




Tips

  • Add the following lines:
    • Order allow,deny
    • Options None
    • Allow Override None
  • If you want to save your time, use XAMPP software bundle. It is most simple way to install Apache, PHP, MySQL on Windows.
    • Be sure to make these last changes to the Apache configuration file to prevent a 403 FORBIDDEN message when testing to see if PHP has been successfully installed:
      • <Directory "c:/php/">
      • </Directory>
      • Allow from all

Related Articles