January 16, 2009 3:25 pm GMT
Installing PHP 5.x on Apache – Windows 7 (beta) in CLI mode
by Gary Illyes- First, download the latest PHP as a Windows binary from PHP.net. Download the ZIP package, not the installer. When this is done, create a directory named PHP5 in the root of the hard drive/partition where Windows 7and Apache are installed, and unpack the downloaded ZIP package into the created directory.
- Now go in the directory you installed Apache. If you followed our Apache on Windows 7 How-to article, Apache is most likely situated in
C:\Program Files\Apache Software Foundation\Apache2.2\; open that path in Windows Explorer (or just navigate there from My Computer), access the ‘conf’ directory and open in Notepad the file named httpd.conf - Now we need to tell where the PHP Apache modules are situated. They are in the root of the directory where you unpacked PHP. So to let Apache know about it, put the following lines in the top of the httpd.conf:
LoadModule php5_module "c:/php5/php5apache2.dll"
#for Apache 2.2 comment the line above
#and uncomment the below one
#LoadModule php5_module "c:/php5/php5apache2_2.dll"
AddType application/x-httpd-php .php# configure the path to php.ini
PHPIniDir "C:/php5"Choose Save as… from the File menu, as location choose Desktop, Save as type should be All files and File name: httpd.conf.
- When saved, navigate again to the Apache install directory, access again the conf folder and drag here the httpd.conf you saved on your desktop
- Start up Command Prompt as Administrator (right-click command prompt shortcut and choose Run as Administrator) and navigate to the Apache install directory. Access the Apache2.2/bin directory and type the following in the prompt:
httpd.exe -k install
If everything is cool, Apache will inform you that the service has been installed. If there’s an error, it will tell you what’s the problem. - Now let’s fire up Apache and create a php file to see if PHP is running. In the comment prompt started as Administrator type
httpd.exe -k -start
Navigate to the Apache install directory and access the htdocs folder. Minimize this window, create a new text file on the Desktop, name it test.txt. Open it with Notepad, and put the following 3 lines in it:
<?php
phpinfo();
?>
From the file menu choose Save as…, location should remain Desktop, name it test.php and Save as type: All files. Finally, drag the new PHP file on the minimized htdocs folder. - Open up your favorite browser and type in the address bar:
localhost:8080/test.php
If everything went OK, you should see something like this:
For installing PHP on the native web-server of Windows 7 , IIS, please see this tutorial.
Have questions? Ask in the comments sections!


















Francisco on Sat, 17th Jan 2009 10:41 pm
Hi from Spain.
Im running Windows7, and… i installed AppServ, but to type localhost in the internetExplorer….error!
I edited the file httpd.conf, and… to write in the cmd httpd.exe -k start, says that in the line ‘PHPIniDir’ have an error……… why??
The service mysql its running, but…. apache & php not running
Regards from Spain.
methode on Sun, 18th Jan 2009 6:34 am
Hello Francisco,
First of all, we never recommend using packages like AppServe.
But I guess it should work, so let’s debug it: I need to now the directory where PHP got installed. Usually it’s c:\php.
Then you will have to stop the AppServ, enter the command prompt as administrator, and start/install all the services manually.
But first tell me the php install directory.
ChrisW on Thu, 29th Jan 2009 10:39 pm
I cannot get PHP to install correctly, or that’s what it seems like. I have a specific httpd.exe config for the sites I work on and it worked fine in Vista so I’m not sure whats going on. Basically, I connect to the local host using virtual hosts and the initial page loads correctly. However, the next page I select is rendered partially and then any link after that loads the raw html.. I’ve tried it any way I can and I noticed installing PHP using the Windows installer generates an error. Installing it to C:\PHP makes everything work, but the issues descibed above continue to occur. I’m so close, but it’s killing me!! Thanks for any help you can give me. I’m running PHP 5.2.8, Apache Web Server 2.2.11, and Windows 7 x64.
methode on Fri, 30th Jan 2009 6:31 am
Hello Chris,
I didn’t encounter such situation yet so I will give you advices regarding how to start debugging the issue in the way I would do it.
I don’t think that PHP is the guilty, rather Apache is. If am correct, I’d like you to check the Apache handlers because these are what tells a browser what to do, for example a HTML file, or these will make PHP to compile and run your PHP code.
Please make sure that these two lines are added in your httpd.conf
LoadModule php5_module “c:/php5/php5apache2_2.dll”
AddType application/x-httpd-php .php
(be aware that this commenting engine uses smart quotes, you will have to change the quotes in your httpd.conf else you will get only errors)
Also remember that when you change something in the httpd.conf, you have to restart Apache in order the changes to take effect. And, if you’ve set Apache to send caching requests to the browsers, you will have to clear the browser cache to see the effect of your changes.
Please do let me know if this helps, I will think about something else if it doesn’t.
ChrisW on Fri, 30th Jan 2009 2:34 pm
Where does the AddType code go? I found the section of the httpd.conf file that has the AddType specific relation to compression. The LoadModule path is correct in my config as well.
ChrisW on Fri, 30th Jan 2009 2:47 pm
HA! Never mind, I got it sorted out, forgot a space between x-httpd-php and .php!! That was all it took, everything behaves normally now. Thanks so much for your help!!!
Chris
methode on Fri, 30th Jan 2009 3:33 pm
Hi again Chris,
Glad it helped. Please remember that almost always when a specific filetype isn’t rendered by the webserver (Apache in this case), is very likely that there’s a typo or error in your configuration files.
Also, I’d like to point you to a new thing we introduced: http://devoracles.com/contact/?what=ask
Basically, if you have any time of issue with your webserver, code or if you have an IT&C related question in general, we will do our best and get a solution for your problem in a timely manner (~24 hours the most). For free and with very much pleasure, of course.
Have a great day
Khairul Syahir on Thu, 21st May 2009 2:19 am
I’ve installed Apache2.2 and PHP5 and all seem to be working perfectly, except that I cannot get PHP to display errors and warnings at all. I’ve set error_reporting = E_ALL and display_errors = On, but no error is shown.
I intentionally made a mistake in the php code to test it out. All that is displayed is a blank page. There’s not even a single html code.
The error does get recorded in the log file though.
Would really appreciate it if you could help me.
Gary Illyes on Thu, 21st May 2009 1:57 pm
Hi,
If you write a code, is that executed?
If it is, is that your problem that the warning/error isn’t displayed on the browser window?
Khairul Syahir on Thu, 21st May 2009 9:39 pm
If the code doesn’t have any fatal error, it’ll execute just fine, so I know PHP itself is working. But if there’s a fatal error, say I missed a “;”, the browser just displays a blank page, without any error notification at all. Using the View Source function of the browser, it shows that the page doesn’t even have any HTML at all.
Gary Illyes on Fri, 22nd May 2009 4:24 am
Where did you set display_errors, on runtime or configuration level?
If on runtime, that is the problem as the php engine tries to parse the whole script, it finds a fatal error thus nothing is executed.
Khairul Syahir on Sat, 23rd May 2009 4:41 am
I believe it’s at the configuration level. I set the display_errors as well as error_reporting values in the php.ini file.
Kutt Katrea on Tue, 7th Jul 2009 1:47 pm
I’ve installed Apache + PHP 5 on Windows 7 RC and it works fine… except when mysqli extension is used, because it make Apache crash.
Alex V. on Tue, 14th Jul 2009 1:01 am
I am running Windows 7 Beta x64, have Apache and MySQL installed fine, PHP5 is also installed but it won’t run citing: “PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\webdev\php5\ext\php_pdo_mysql.dll’ – The specified module could not be found.
in Unknown on line 0″
i have redownloaded the php5 and replaced the ext folder, and the path it is addressing is valid and the file is there. any help is appreciated.
argenis on Wed, 21st Oct 2009 2:33 am
hello sr.gary. ive installedeverythin like u said apache 2.2 + php5 but when im gona do the step No.6 when i type httpdexe -k -star its says : syntax error cannot load c:/php5/php5apache2.dll into serve: cant find the module specified
————————————
i have checked and the path is ok…. i cant find te error :S plz help plz plz
Agustin on Fri, 23rd Oct 2009 11:38 am
Alex V:
Because we use a new version of apache v2.2.x we have to comment the first line and un-comment the fourth so it have to be:
#LoadModule php5_module “c:/php5/php5apache2.dll”
#for Apache 2.2 comment the line above
#and uncomment the below one
LoadModule php5_module “c:/php5/php5apache2_2.dll”
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir “C:/php5″
Soye on Wed, 25th Nov 2009 7:00 am
I’ve followed the instructions as stated however when i try to run the php script via a browser its simply blank. I’ve rechecked everything and it all seems fine to me. I am running this on an x64 system though. I’m thinking that maybe the issue. What do you think?
omidt on Fri, 27th Nov 2009 4:55 am
not work on win 7,
localhost not responding.
Andy on Wed, 6th Jan 2010 12:08 pm
Works great thanks for putting this up. Am now going to try your other tutorial for PHP.
aNDY on Wed, 6th Jan 2010 1:47 pm
Added the code Augustin menitoned above and removed the commas and retyped them and bingo. It works fine. Many thanks for this tutorial. Much needed and useful. Thanks and God Bless.
DAVE. on Sun, 24th Jan 2010 6:53 pm
to: Soye
I got the blank page afer have apache2.2 and php5 running. Fininally, I found the problem was with the php.ini. If we dont change the original php.ini-recommend to php.ini, Php5 will up and running. I dont know why, but that seems the problem.
Ed on Sun, 31st Jan 2010 7:17 pm
Guys,
Thanks for the discussion. I was able to follow the fixes and get Apache (apache_2.2.14-win32-x86-openssl-0.9.8k) running w/out any issues. However, PHP (php-5.3.1-nts-Win32-VC6-x86) doesn’t wanna play nice. Am getting the following error. BTW, my environment is Win7, Home Premium (not Beta or RC) x64.
c:\PROGRA~2\APACHE~1\Apache2.2\bin>httpd.exe -k start
httpd.exe: Syntax error on line 4 of C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/httpd.conf: Cannot load C:/php5/php5apache2_2.dll into server: The specified module could not be found.
I’ve looked everywhere for this file, php5apache2_2.dll, to no avail. I even downloaded the debug (php-debug-pack-5.3.1-nts-Win32-VC6-x86) file in hopes to find it there…no dice.