PHP: Installing PHP

Installing PHP

PHP is a scripting language that is best suited for web applications. When a user types in an address in their web browser, if the web page at that address has PHP code in it and has a .php extension, then a couple of things happen:

  1. The PHP code executes on the server.
  2. The output from the PHP execution is inserted into the web page.
  3. The web page is sent to the user's browser in the form of HTML.

This lesson assumes that you have the Apache web server installed on your local machine. If you do not, please go over our Installing Apache Web Server tutorial first.

To install PHP on your local machine, follow these steps:

  1. Click http://windows.php.net/download/ to take you to the Windows subdomain of the PHP language website. This page specifically is the Windows download page.
  2. From the pull-down menu, pick the VC6 or VC9 Thread Safe version of PHP. We use the VC6 version because we are installing it on top of the Apache web server.
  3. Click on the "Installer" link in the VC6 or VC9 Thread Safe section.
  4. When the download dialog appears, click Run.
  5. After the file downloads, the Security Warning will appear. Click Run.
  6. When the installation wizard dialog first opens, click Next.
  7. To accept the license terms, check "I accept the terms in the License Agreement" and click Next.
  8. Choose the default Destination Folder and click Next.
  9. Here, select the "Apache 2.2.x Module", then click Next.
  10. On the next dialog, browse to find the Apache configuration folder. For the default Apache installation, the path is: C:\Program Files\Apache Software Foundation\Apache2.2\conf\. Click Next.
  11. Leave the default installation choices as is and click Next.
  12. Click Install to begin the actual installation.
  13. It may take a couple minutes to install. During install, a "User Account Control" dialog may pop up; click Allow to proceed.
  14. Click Finish to exit the installation.


Apache Configuration

  1. Go to C:\Program Files\Apache Software Foundation\Apache2.2\conf\.
  2. Open the httpd.conf file in Notepad or another text editor.
  3. Find this text in the file:
  4. <IfModule dir_module>
        DirectoryIndex index.html
    </IfModule>
    

    and change it to this:

    <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>
    
  5. Next, you may have to fix an error in the PHP install. Search for this text:
  6. #BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
    PHPIniDir ""
    LoadModule php5_module "php5apache2_2.dll"
    #END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
    

    If the PHPIniDir variable is empty, and the LoadModule php5_module only has the .dll name and not the full path, you'll need to add paths to each, like this (I use the default install path here):

    #BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
    PHPIniDir "C:\Program Files (x86)\PHP"
    LoadModule php5_module "C:\Program Files (x86)\PHP\php5apache2_2.dll"
    #END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
    
  7. Save the file.
  8. Go to your taskbar.
  9. Right-click on the Apache Monitor icon and select "Open Apache Monitor".
  10. Restart the Apache2.2 Server.
  11. Click OK.

Now you have successfully installed PHP and configured it to run on the Apache web server on your local machine.



If you have any questions or comments, please post them in our Forum.