PHP is a general purpose server-side scripting language designed to generate dynamic web pages. It is among one of the first developed server-side scripting languages that is embedded into an HTML source document, rather than calling an external file to process data. In this article we are going to configure PHP with Apache.

Downloading PHP

You can download PHP from Download PHP for Windows. I downloaded VC9 x86 Thread Safe zip package.

Installing PHP

  • Extract all the files from the zip package downloaded.
  • Put all files/folder into a folder e.g. C:\PHP. I put all files/folders into D:\hMailServer\php.

Installing Apache

Install Apache Server on Windows. Follow Install Apache Server on Windows for detailed description.

Configure PHP with Apache

  • Open the file “httpd.conf” located in “apache_installation_folder\conf” folder. In my case httpd.conf is in “D:\hMailServer\Apache2.2\conf”
  • Rename “php.ini-development” to “php.ini” located in PHP installation folder.
  • Add below lines in httpd.conf file. Please replace the installation path and while doing so please remember to replace all back slashes with forward slashes.
# Add these lines to configure PHP with Apache
LoadModule php5_module "D:/hMailServer/PHP/php5apache2_2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "D:/hMailServer/php/"

Testing the PHP

  • Create a simple a new file having below contents:
        <title>Test PHP Installation</title>
            echo "You have successfully configured PHP with Apache";
  • Save this file as test.php in htdocs folder of your Apache installation folder. In my case it is “D:\hMailServer\Apache2.2\htdocs”
  • Browse “http://localhost/test.php”. If “You have successfully configured PHP with Apache” message appears in your browser means successful configuration of PHP with Apache Web Server.

Configure PHP with Apache : Testing PHP

Related Posts

One thought on “Configure PHP with Apache

  1. Hi Guys,

    I have an update regarding above article. When I wrote above article I tested it on my Windows 7 – 32bit Operating System and it worked fine. After a few days I tested it on Windows 2008 Server Data Center Edition – 64 bit operating system and I was unable to start Apache HTTP Server.

    While starting apache2.2 service from command prompt I was getting below error:

    C:Windowssystem32>net start apache2.2

    The Apache2.2 service is starting.
    The Apache2.2 service could not be started.

    A service specific error occurred: 1.

    More help is available by typing NET HELPMSG 3547.

    Then I tried httpd -t command and was getting below error:

    C:Program Files (x86)Apache Software FoundationApache2.2bin>httpd.exe -t
    httpd.exe: Syntax error on line 131 of C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/httpd.conf: Cannot load C:/PHP/php5apache2_2.dll into server: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.

    I tried starting apache2.2 service after installing Microsoft Visual C++ redistributable package for X64, but still I was getting same error:

    Finally, I downloaded PHP 5.2.17 and apache2.2 service started successfully.

    If anybody has solution with PHP 5.3.8, please let me know. I have yet not tested PHP 5.3.9.


Leave a Reply