How to install PHP on Windows 7

Before installing PHP you need to install Apache Server first and make sure that it's running properly.

Download the latest version of PHP at

Download the zip version with thread safe as shown below.

PHP Install-01

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:

doc_root =

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:

;upload_tmp_dir =

Uncomment it and add path to the upload folder we've just created:

upload_tmp_dir= "C:\Apache\temp\upload"

And the next line:

;session.save_path = "/tmp"

Uncomment it and add path to the session folder:

session.save_path= "C:\Apache\temp\session"

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.

PHP Install-02

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.

PHP Install-03

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

Add index.php to the line

<IfModule dir_module>
    DirectoryIndex index.html index.php

PHP Install-04

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"

PHP Install-05

Add the following lines to the end of the httpd.conf

PHPIniDir "C:/Apache/php/"
LoadModule php5_module "C:/Apache/php/php5apache2_2.dll"

PHP Install-06

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 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)

If you are installing PHP7 on Apache 2.4 load "php7apache2_4.dll" module.

LoadModule php7_module "C:/Apache/php/php7apache2_4.dll"

End of update

Restart Apache Server.

Testing PHP.

Open up Notepad, copy and paste the code below:


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.

PHP Install-07

If you did it right, you should see something like the image above.

In the next chapter we will install MySQL.


  1. thaks for this information..

  2. THANKS alot for the information.

  3. Thanks for the information

  4. Thanx a lot Buddy... :D

  5. Great!! You are too good

  6. im using tomcat7, my tomcat installation path is "C:\Tomcat7" i couldn't find the file named httpd.conf. please help me.

    1. Are you sure PHP can run under Tomcat 7?, this PHP installation is for Apache HTTP Server.

    2. I just found a link, you can run PHP version 4 on Tomcat 7

    3. so.. i can't run php version 5 on tomcat7?

    4. According to their statement, you can't run php version 5 on tomcat 7.

      "PHP version 5 is not currently supported as it does not include the necessary servlet code"

  7. apache is unable to start when i put these lines in httpd file

    PHPIniDir "C:/Apache/php/"
    LoadModule php5_module "C:/Apache/php/php5apache2_2.dll"

    Otherwise it is able to start
    plz tell me what do I do?

    1. What is your Apache version?

      Apache 2.2.+ ( works with PHP VC6 5.2 and older versions.

      Apache 2.2.+ ( works with PHP VC9.

      If you are using Apache 2.4.+ load module php5apache2_4.dll.

      LoadModule php5_module "C:/Apache/php/php5apache2_4.dll

  8. great tutorial ... thanks a lot...

  9. Hi!
    am running Apache 2.4.3 and PHP 5.4.12
    but i cant load("C:/Apache/php/php5apache2_4.dll"

    any help please?

    1. I'm also using the same versions and they are running just fine. Try to start Apache from the Command Prompt by typing: "httpd -k start" It'll give you some clues about the problem. And make sure your PHP is Thread Safe

    2. I'm having the same problem too. I've ran the command prompt as you have just suggested and it returns the error of:

      httpd: Syntax error on line 532 of C:/Apache/conf/httpd.conf: Cannot load C:/Apa
      che/php/php5apache2_4.dll into server: %1 is not a valid Win32 application.

      Any ideas of how to solve this?

      Great guides by the way, regards.

    3. As you didn't tell me the versions, so I can only guess, perhaps you're using the wrong binaries. I recommended to use Apache VC9/VC10 Win32 binaries with PHP VC9 thread safe even if you're running Windows 7 64Bit.

    4. Hi and thank you for your reply.

      I have resolved the issue now. It was due to the fact i was running Apache 2.4 64bit with a 32bit version of php 5.4.13. Seemed to cause some conflict when adding the "LoadModule php5_module C:/Apache/php/php5apache2_4.dll" line to the end of the httpd.conf file.

      I have since downloaded a 64bit version of php 5.4.12 which is now operating correctly with the version of Apache I'm running.

      Again, thank you for your respone.


    5. You're welcome, Glad to hear that :-)

  10. I'm using php-5.2.17-Win32-VC6-x86 and httpd-2.0.64-win32-x86-no_ssl
    I have the same problem too..
    If I add these lines below, the server won't start...
    PHPIniDir "C:/Apache/php/"
    LoadModule php5_module "C:/Apache/php/php5apache2_2.dll"

    But I can run php just fine without those lines...
    So, I'm just curious what's the function of those lines since I can run php without it..

    1. php5apache2_2.dll is for Apache 2.2 x
      For Apache 2.0 x, use php5apache2.dll

      LoadModule php5_module "C:/Apache/php/php5apache2.dll"

  11. Awesome Job! Works perfect ThanQ

  12. Thank you, very detailed tutorial.

  13. Thanks you so much for a good guide. I ran into problems but from this same article I was able to find out its because I mixed 32-bit and 64-bit. Thanks and God bless you.

  14. Why is it necessary that I use VC9 on this? I read your tutorial on installing Apache on Windows x64. tells us to use VC6 for Apache 2.2. Thanks

    1. It depends on what Apache you're using.
      If you're using Apache from "" you should use PHP VC6. If you're using Apache from "" you should use PHP VC9.

  15. Hi there. Having quite a problem here. Im currently using httpd-2.4.4-win32 for Apache and php-5.2.17-Win32-VC6-x86 for PHP. My Apache won't start and it says

    httpd: Syntax error on line 536 of D:/Apache/conf/httpd.conf: Cannot load D:/Apache/php/php5apache2_2.dll into server: The specified procedure could not be found.

    Any ideas?

    1. php5apache2_2.dll is for Apache 2.2 x
      For Apache 2.4 x use php5apache2_4.dll

      LoadModule php5_module "D:/Apache/php/php5apache2_4.dll"

    2. I had this problem too. If you are installing x64 version of apache, you need to install also x64 version of PHP. This is must. Change to php5apache2_4.dll does not help here. Google for x64 php, as it is not on download page. Admin, please mention this in article. Anyway, thank you for so great HOW TO !!!

  16. i am not able to find DIRECTORYINDEX in httpd.conf file.

    please help?

    1. With Notepad you can use find option (Ctrl+F)

      Mine is line 271 (opened with Notepad++)
      I am using Apache 2.4.4 by the way.