本节包括在 Microsoft Windows 系统中针对 Apache 2.x 安装 PHP 的指导与说明。在其它页面也有 Apache 1.3.x 用户指导与说明。
Note:
应该先阅读手工安装步骤!
Note: Apache 2.2 支持
Apache 2.2 用户应留意对于 Apache 2.2 的 DLL 文件名是 php5apache2_2.dll 而不是 php5apache2.dll,并且只在 PHP 5.2.0 以及更高版本中出现。参见 » http://snaps.php.net/。
强烈建议阅读 » Apache 文档来加深对 Apache 2.x 服务器的基本理解。此外在继续下去之前考虑先阅读一下 Apache 2.x 的 » Windows 下使用说明。
Apache 2.x 被设计运行于 Windows 版的服务器平台下,例如 Windows NT 4.0,Windows 2000,Windows XP 或 Windows 7。虽然 Apache 2.x 可以在 Windows 9x 下勉强运行,但对此平台的支持尚未完成,某些功能无法正确工作。对此并无补救计划。
下载最新版本的 » Apache 2.x 以及适合的 PHP 版本。先完成手工安装步骤后再回来继续将 PHP 集成入 Apache。
Windows 下有三种方法使 PHP 工作于 Apache 2.x 之中。可以以 handler,CGI,或者 FastCGI 方式运行 PHP。
Note: 记住当在 Windows 环境下的 Apache 配置文件中添加路径值时,所有的反斜线,如 c:\directory\file.ext,应转换为正斜线: c:/directory/file.ext。对目录来说,也必须由斜线结尾。
需要将以下几行加入到 Apache 的 httpd.conf 配置文件中以加载 Apache 2.x 的 PHP 模块:
Example #1 PHP 在 Apache 2.x 中作为 handler
# LoadModule php5_module "c:/php/php5apache2.dll" AddHandler application/x-httpd-php .php # 配置 php.ini 的路径 PHPIniDir "C:/php"
Note: 记得用自己 PHP 实际所在的路径替换掉上例中的 c:/php/。要留意在 LoadModule 指令中使用了 php5apache2.dll 或者 php5apache2_2.dll,并且该文件确实位于所指定的位置。
以上配置将使 PHP 处理任何具有 .php 后缀的文件,即使该文件还有其它的文件后缀。例如一个名为 example.php.txt 的文件将被作为 PHP 文件运行。要确保只有以 .php 结尾的文件才被执行,则用以下配置替换上面的:
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
要更好地理解在 Apache 下运行 CGI,请参阅 » Apache CGI 文档。
要将 PHP 以 CGI 方式运行,需要将 php-cgi 文件放入到用 ScriptAlias 指令所指定的 CGI 目录中。
然后需要给 PHP 文件中添加一 #! 的行来指明 PHP 可执行文件的位置:
Example #2 Apache 2.x 下 CGI 方式的 PHP
#!C:/php/php.exe <?php phpinfo(); ?>
服务器使用 CGI 方式进行部署可能存在几个公开的缺陷。请阅读 CGI 安全一章 以学习 如何抵御这些攻击。
以 FastCGI 方式运行 PHP 比起 CGI 方式有很多优点。设定的方式很直接:
从 » http://httpd.apache.org/mod_fcgid/ 取得 mod_fcgid,该站点有 Win32 可执行文件的下载。按照下载文件中的指示安装此模块。
按以下方法配置 web 服务器,注意用自己系统上的路径替换其中相应的内容:
Example #3 配置 Apache 以 FastCGI 方式运行 PHP
LoadModule fcgid_module modules/mod_fcgid.so # Where is your php.ini file? FcgidInitialEnv PHPRC "c:/php" AddHandler fcgid-script .php FcgidWrapper "c:/php/php-cgi.exe" .php
Amaroq (2013-03-28 10:53:30)
Like someone else mentioned, on the Windows download page for PHP, ignore the warning about not downloading the VC9 compiled installers for the Apache.org version of Apache.
Whoever wrote that is guaranteeing that people install a PHP that breaks their Apache server. (On Windows 7 anyway.) The installer failed to write the correct path info to httpd.conf, and even after fixing that manually, Apache wouldn't start because of missing dlls.
Ignore that dumb warning and get the newest installer anyway. Everything just plain works with no hassle and no hunting down dll files over google.
Maw (2013-01-31 21:26:05)
Good God finally I was able to make PHP 5.2 work on Apache 2.4. For those still having problems with "You don't have permission to run php-cgi.exe", you must replace "Order allow,deny" and "Allow from all" from the PHP directory block with "Require all granted". They must have changed the format with Apache 2.4 since the old method used to work just fine for me before.
So the usual method of setting up CGI, I'm sure you already know that you should add these 3 lines to httpd.conf:
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php-cgi.exe"
And now add the directory for PHP:
<Directory "c:/php">
AllowOverride None
Options None
Require all granted
</Directory>
Important: Notice that instead of "Order allow,deny" and "Allow from all" added into the PHP directory as usual, I replaced them with "Require all granted" as I mentioned above.
o.machala[at]email[dot]cz (2012-11-02 14:17:39)
If you have a problem "The requested operation has failed!" and LOG says "Module php5apache2_2.dll not found" and have:
PHPIniDir "P:\PHP\"
LoadModule php5_module "P:\PHP\php5apache2_2.dll"
in httpd.conf make sure you have installed the apache2.2 (not apache 2.0 or earlier versions). It was my problem and i downloaded correct version from http://www.apache.org/dist/httpd/binaries/win32/ and everything just works.
kriss266 at o2 dot pl (2012-08-21 14:02:33)
[For the error:] You don’t have permission to access /php/php-cgi.exe/index.php on this server.
In order to fix the forbidden error I had to change this line in httpd.conf:
<Directory “C:/Server/Apache2.2/cgi-bin/”>
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
to this:
<Directory “c:/Server/php”>
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
auser at example dot com (2012-06-11 17:42:34)
To be clear:
AddHandler application/x-httpd-php .php
means any file with ".php" in it becomes a php file. Test it out, name a file "test.php.dontrunme", and it will be processed as a php file.
If you want ".php" to be used only when it is the last part of the filename, use:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
But *also* remove: AddHandler application/x-httpd-php .php
or comment it out:
#AddHandler application/x-httpd-php .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
a solution for simpletons like me (2012-04-25 19:54:00)
Installing Apache and PHP on Windows 7 Home Premium on a Gateway NV75S laptop with a quad AMD A6-3400M
All I need to do with these programs is to test my website out on my laptop. I have HTML and PHP files. I do not need MySQL as I use html5 storage.
Getting and installing Apache
1 In your browser go to h t t p : / / h t t p d . a p a c h e . o r g / d o w n l o a d . c g i
(without the spaces)
2 Click on httpd-2.2.22-win32-x86-no_ssl.msi
(this is a self-installing executable file without crypto ... no Secure Socket Layer)
(2.2.22 was the latest version on April 25, 2012)
3 Click on the httpd-2.2.22-win32-x86-no_ssl.msi file after it downloads
(single click on the file tab in Chrome or double click on the actual file in Downloads)
4 Click Next
5 Click I accept the terms in the license agreement
6 Click Next
7 Click Next
8 Type localhost in the top box
9 Type localhost in the middle box
10 Type admin@localhost.com in the bottom box
11 Click Next
12 Click Next
13 Click Next
14 Click Install and wait
15 Cick Yes to allow the program to make changes
16 Click Finish
Testing Apache
1 Type localhost in your browser location box (I use Chrome) or type h t t p : / / l o c a l h o s t
(without the spaces)
2 The message It works! should appear.
Getting and installing PHP
1 In your browser go to h t t p : / / w i n d o w s . p h p . n e t / d o w n l o a d /
(without the spaces)
2 Click on the Installer link under PHP 5.3 (5.3.10) VC9 x86 Thread Safe
(Ignore the Do NOT use VC9 version with apache.org binaries comment on the side panel)
3 Click on the php-5.3.10-Win32-VC9-x86.msi file after in downloads
(single click on the file tab in Chrome or double click on the actual file in Downloads)
4 Click Next
5 Click I accept the terms in the License Agreement
6 Click Next
7 Click Next
8 Click Apache 2.2.x Module
9 Click Next
10 Click Browse
11 Double click Apache Software Foundation
12 Double click Apache 2.2
13 Double click conf
14 Click OK
15 Click Next
16 Click Next
17 Click Install and wait
18 Cick Yes to allow the program to make changes
19 Click Finish
Testing PHP with Apache
1 Open Notepad
2 Type 'left bracket character'?php phpinfo(); ?'right bracket character'
3 Save the file to C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs as test.php
4 Type localhost/test.php in your browser location box (I use Chrome) or type h t t p : / / l o c a l h o s t / t e s t . p h p
5 A table with title PHP Version ... should appear
DONE
Gedi (2012-04-15 12:54:32)
I was struggling with configuring PHP 5.2.17. (msi version) for
Apache 2.2.22. on Windows 7. Apache was working before fine.
The following failure message came as I tried to start Apache:
"The requested operation has failed!"
After many hours finally the comment from "bdav 05-Mar-2012 02:23" helped me and the following code in httpd.conf made Apache working with PHP:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
PHPIniDir 'c:\php\'
I hope I can save some hours of frustration to some beginners like me.
Bechesa at gmail dot com (2012-03-15 11:57:18)
Just a note
It might be important you include the absolute path to the php.ini file inside the httpd.conf file so that php may load all the module(s).
below is an example
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir 'C:\PHP\php.ini'
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
OS: windows 2008
webserver: apache2.2
Bechesa at gmail dot com (2012-03-15 11:56:42)
Just a note
It might be important you include the absolute path to the php.ini file inside the httpd.conf file so that php may load all the module(s).
below is an example
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir 'C:\PHP\php.ini'
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
OS: windows 2008
webserver: apache2.2
johanvermeij at gmail dot com (2012-03-14 03:07:10)
I upgraded Apache httpd from 2.2.x to 2.2.21
I am using Eventum bug tracker s/w under Apache
After the upgrade firstly I only saw the "index of" listing for /eventum under DocumentRoot
That was fixed by adding index.php to DirectoryIndex (I missed that while doing a diff)
After fixing that I got a mysql database connect error.
That was fixed by going to my original php directives in httpd.conf (changing php5apache2 to php5apache2_2)
LoadModule php5_module C:/PHP/php5apache2_2.dll
AddType application/x-httpd-php .php
After that eventum was ok again
bdav (2012-03-05 14:23:15)
After spending few hours finally figured out that PHPINIDir path should be in single quotes and with backslash and php module with double quotes and regular slashes:
PHPIniDir 'c:\apps\php\'
LoadModule php5_module "c:/apps/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
Z Carlos at Fortaleza (2012-02-04 22:09:03)
A Thread Safe version should be used if you install PHP as an Apache module. The Non Thread Safe version should be used if you install PHP as a CGI binary.
s_shaw at comcast dot net (2012-01-31 01:50:02)
After installing apache 2.2 (httpd-2.2.17-win32-no_ssl.msi) and php 5.3 (php-5.3.9-win32-vc9-x86.msi) and then navigating to a local directory with php files, the browser only displayed a file listing. Unfortunately, during the php install, windows 7 would not allow the installer to edit the http.conf file... To resolve, I added these lines to the conf:
LoadModule php5_module "C:/program files (x86)/php/php5apache2_2.dll"
PHPIniDir "c:/program files (x86)/php"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
...and updated this line...
DirectoryIndex index.html
to this...
DirectoryIndex index.html index.php
...along with making the appropriate updates that specified the location of the local document root.
...and in php.ini, make sure this update is present:
extension_dir = "c:/yourserverpath/php/ext/"
I also made sure that C:\server\php was listed as an environment variable on the pc...
And finally, make sure you reboot your pc for everything to take...
robert dot nevinger at sbcglobal dot net (2011-12-18 09:34:55)
Apache 2.2 crashing on WindowsXP/Apache2.2/php5.3.8_Win32.VC9-x86
There is a distinction between LoadFile and LoadModule.
LoadModule is typically used to load Shared Objects (.so), and comes in very handy for Dynamically Shared Objects
LoadFile on windows it typically used to load DLL
Please note: In order for a LoadMoudle directive to work on a DLL the module must be compiled into the library. If you use VI you can usually locate the module, but the file is compiled, don't write it!
A dll can be located anywhere on the system.
A .so should be located in your Apache install modules folder.
What worked for me for Windows XP/Apache2.2/php5.3.8_Win32.VC9-x86
PHPIniDir "C:/PHP/"
LoadFile "C:/PHP/libeay32.dll"
LoadFile "C:/PHP/libpq.dll"
LoadFile "C:/PHP/libsasl.dll"
LoadModule php5_module "C:\PHP\php5apache2_2.dll"
This comment is to support the Apache startup, NOT serve PHP pages.
bradley dot henke at colorado dot edu (2011-10-31 13:38:09)
I was able to get apache up and running without any problems. Then I tried installing php and it crashed trying to read "C:/php/php5apache2.dll".
Fixed the problem by switching it to "C:/php/php5apache2_2.dll"
Hope that helps!
Cooldude (2011-08-31 07:56:51)
Also had an exception problem when trying to use mysql with apache and php5.
I had to add:
"<my MySQL folder>\bin" folder to path
"<my php folder>\ext" to path
that fixed it
capesirius at gmail dot com (2011-08-24 04:22:55)
php5ts.dll exception problem
I had the same problem win php5ts.dll. Apache didn't start.
Configuration was: Win 7 + php 5.2.17 + Apache 2.2.19.
And I used .msi php installer.
None of the posts below helped to fix the problem.
Finally the problem was resolved by using .zip php archive instead of .msi.
tcombass at gmail dot com (2011-07-29 14:12:31)
If you are having problems with php5ts.dll...
php5ts.dll is php5.dll but thread safe, hence the 'ts' at the end.
Software Details:
MySQL 5.5
PHP 5.2.17 VC6 Non-thread safe
Apache 2.2.19
Win XP SP3
Here's how I fixed the problem:
I've been looking online on how to integrate Apache with PHP right so I come across this code to put in my httpd.conf apache configuration file:
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
PhpIniDir "C:/php"
I paste it in a voila! it crashes! I know its not news, but I looked and lo and behold its that darn php5ts.dll file!
In short:
I installed PHP 5.2.17 VC6 Non-Thread Safe. I then installed the PHP 5.2.17 VC6 thread safe so I could copy these files from the thread safe installation into the PHP 5.2.17 VC6 Non-Thread safe installation directory:
php5apache2_2.dll
php5apache2_2filter.dll
Not sure if that last file is needed but I added it anyway.
Then I uninstalled the thread safe installation.
The Apache service started right up.
Had some problems with MySQL too:
When I installed it the first time it was fine. Then I uninstalled it and got that "Service could not be started Error: 0" message.
To do a complete deletion do this:
1) Use MySQLInstanceconfig.exe to remove the service
2) Use the "Add/Remove programs" to uninstall MySQL
3) Delete the "c:\program files\MySQL directory"
4) Delete the "c:\documents and settings\All Users\Application Data\MySql\" directory
5) Launch regedit.exe from START>RUN and press ctrl+f for the find function and type in MYSQL to find and get rid of anything "MySQL" in there. Press F3 to find repeat instances of "MySQL"
I hope this helps you. I spent about 30hrs uninstalling and reinstalling this crap...
Cameron (2011-05-14 23:37:43)
Here is yet another aspect of the "faulting module php5ts.dll" crash when trying to start apache.
I installed Apache 2.2.18, Mysql 5.1.57 and PHP 5.2.17 (apache module, VC6 thread-safe - initially with no extensions) on a fresh WinXP SP3 system. The versions chosen were because I was trying to replicate as near as possible apps on my Linux server.
Everything configured and ran properly without php extensions, so I then reran the msi installer and chose the necessary extensions. I reconfigured httpd.conf but apache then just kept crashing.
Eventually I came across the "fix" mentioned elsewhere "copy libmysql.dll to apache folder" and suddenly it worked. But why? I checked and the php installation folder was in the system path. The answer was simply that I had never rebooted. It seems that whatever process controls windows services only reads the path at boot time. I was thrown by assuming that if I started httpd from the command line then it would inherit that path.
Here are a few diagnostic tips that helped me along the way:
Try the CLI command:
php -m
and see that the command line version loads all the modules you asked for.
in php.ini, enable
display_errors = On
and
display_startup_errors = On
The latter pops up a window saying which extension it has trouble loading. Of course it is not perfectly clear, because it says something like 'unable to load "C:\php\ext\php_mysql.dll" - The specified module could not be found'. It lies - it really does find that dll, but it must have failed on the dependency of libmysql.dll.
mike at supergrowlasers dot com (2011-04-28 18:44:59)
I just spent 5 hours repeatedly trying, usuccessfully, to get Apache to parse php files instead of sending them to the browser. I am setting up a Win 7 Pro box, and went through the configuration several times, as well as trying other configuration directives I found elsewhere by searching.
Nothing worked. I was tearing my hair out and ready to cry. I have set this up numerous times on XP with no problem. But on Win 7 Pro it wasn't happening.
Eventually I found this code, which worked perfectly (after taking out directives from httpd.conf that weren't working, of course)
LoadFile "C:/php/php5ts.dll"
LoadModule php5_module "C:/php/php5apache2.dll"
<IfModule php5_module>
#PHPIniDir "C:/Windows"
#PHPIniDir "C:/Winnt"
<Location />
AddType text/html .php .phps
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
</Location>
</IfModule>
If you've been having the same problem, try this.
You're welcome.
brokenarrow218 at rochester dot rr dot com (2011-02-07 00:29:57)
man I had a heck of time.. I was really starting to think I was just too simple minded.. I run PHP on iis7 as well as apache.. my os is win7 pro.. my host uses php 5.2 sooooo..
to run on apache 2.2 download nonthread safe version (my case VC6 x86 Non Thread Safe (2011-Jan-06 18:38:35)) and add this to the end of your apache httpd.conf file
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "c:/php/"
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
fired right up..
yakfish (2011-01-25 13:43:13)
If Apache won't start after PHP install, check for this scenario:
When I followed the instructions for the Windows installer, using Apache HTTP server 2.2.17, the install completed normally but Apache would then fail to start. It turned out that the installer was not properly configuring the last section of Apache's httpd.conf file:
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "c:/php/"
LoadModule php5_module "c:/php/php5apache2_2.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
The text above is the correct configuration (in my case, I had asked the installer to place PHP into directory C:/PHP.) However, the installer omitted the string "c:/php/" from the two lines above where you can see them. I had to edit the file, and add that string in manually, before Apache would start correctly.
pkay(number42) at gmail dot com (2010-12-30 09:31:06)
Running Apache2.2 on Windows 7. There was no php5apache2_2.dll on my system, and all I got was a message box "The requested operation has failed!" (no, that's not OK).
Finally realized that thread-safe version (VC6, mind!) was necessary - it had the dll in it.
Downloaded that, apache runs with
LoadModule php5_module 'C:/Program Files (x86)/PHP/php5apache2_2.dll'
#etc
farinspace (2010-11-20 11:36:29)
Running PHP under FastCGI:
Besides the following in your httpd.conf
LoadModule fcgid_module modules/mod_fcgid.so
FcgidInitialEnv PHPRC "c:/php"
AddHandler fcgid-script .php
FcgidWrapper "c:/php/php-cgi.exe" .php
Remember to add the following to the default <Directory "C:/apache/htdocs"> block (or virtual host blocks):
Options ExecCGI
lebovskiy at ua dot fm (2010-11-16 22:59:03)
I install httpd-2.2.17-win32-x86-openssl-0.9.8o.msi and after
php-5.3.3-Win32-VC9-x86.msi on WinXP SP3. PHP installation add to httpd.conf next lines:
LoadModule php5_module "C:/PHP/php5apache2_2.dll
"PHPIniDir "C:/PHP"
After it Apache don`t starts. If remove PHPIniDir line Apache starts ok, but C:/PHP/php.ini don`t loaded. So you can`t use any extension (for me it's MySQL).
I uninstall VC9 version and install VC6 (php-5.3.3-Win32-VC6-x86.msi) version. All works fine now.
halmai (2010-11-15 03:42:54)
I wanted to install PHP5.3 for Apache2.2 with PostgreSql 9.0 support on WindowsXP. It took me hours to solve it.
The following possible problems occur:
- You should use the VC6-compiled version of php instead of VC9. The later one does not work properly with apache.
- the postgres handler dlls are not working in PHP5.3.
The symptom was a misleading and very confusing error message:
Unable to load dynamic library 'c:\Progra~1\PHP\ext\php_pgsql.dll'
The dll itself was there but when it started to load the other dll (libpq.dll) from the php directory then this caused an error. This error was misinterpreted internally in the above message.
The solution was NOT to use the libpq.dll from php but use it from postgres distribution instead.
For this purpose I inserted the following line into the apache httpd conf:
LoadFile "C:/Progra~1/PostgreSQL/9.0/bin/libpq.dll"
This preloads the dll. When php_pgsql.dll would load his own libpq.dll, then there is the preloaded version of this file in the memory already. This prevents us from using the bad version of dll.
I hope I helped.
terry_513 at yahoo dot com (2010-10-08 08:53:37)
I have installed PHP5.3.3 and Apache2.2.1 successfully on c:/webserver and php on cL/webserver/php. Inidividually both are working.
All manuals show to add loadModule
LoadModule php5_module "c:/webserver/php/php5apache.dll"
with php5apache2.dll or php5apache2_2.dll. But in my PHP folder, I have php5apache.dll.
On setting LoadModule, AddType & PHPIn
LoadModule php5_module "c:/webserver/php/php5apache.dll"
PHPIniDir "C:/webserver/php/"
...
AddType application/x-httpd-php .php
to http.conf, apache2 doesn't work. It pops up "The request has failed". No errors in logs. But apache doesn't work. If I remove these 3 lines, then it works perfectly.
I changed "/" and "\", removed "/" after php in phpini line, but no success. In php.ini file also for setting extension, I had to enter just the "ext" and not full path to make it work.
Can anynoe tell what could be the point, and how to solve it. I am looking badly to setup this and start working. any help is highly appreciative.
Thanks,
Nick (2010-06-16 06:48:26)
After using the Windows installer for Apache 2.2 and PHP 5.3.2, and installing PHP as an Apache module (not CGI), Apache would crash and fail to start. There were two problems with the configuration files for Apache and PHP.
First, make sure your Apache configuration file reads something similar to:
LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"
PHPIniDir "C:/Program Files/PHP/"
While other users have disabled some or all of the MySQL extensions to prevent all three from running at the same time, I have all of them enabled. However, I do not have PostgreSQL, so I needed to comment out loading the php_pgsql.dll in my php.ini file, as follows:
;[PHP_PGSQL]
;extension=php_pgsql.dll
This stopped Apache from crashing and started successfully.
Michael (2010-03-03 09:48:46)
The value for FcgidWrapper cannot contain spaces..
This won't work:
FcgidWrapper "c:/program files (x86)/php/php-cgi.exe" .php
But this will:
FcgidWrapper "c:/progra~2/php/php-cgi.exe" .php
Steve (2010-02-23 16:53:33)
I also had a problem with the PHPIniDir declaration. This is with Apache 2.2 on XP. I had to include a final slash, as in PHPIniDir "C:\Program Files\php\". Apache failed to start if I did not include the slash after php.
Kerry Kobashi (2009-12-13 22:56:44)
If you find that Apache crashes when you attempt to start it, its likely that one of the PHP extensions is the cause. This is likely the case if you use the PHP Windows installer and choose all extensions in the setup program to be installed on disk. Unfortunately, it will also enable all extensions too causing potential problems.
For example, after installing PHP 5.2.11 and Apache 2.2 under Windows XP, Apache kept crashing. This was due to using all three versiosn of mysql extensions attempting to run:
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
Anonymous (2009-12-10 01:25:33)
If anybody here encounters an error regarding PHPIniDir, change PHPIniDir "C:/php/" to PHPIniDir "C:\php\".
nicolas dot grasset at gmail dot com (2009-07-07 10:08:14)
Here is how I created a silent install for Apache2.2 and PHP5.2.10 on Windows XP (running on a MacBook Pro):
Download Apache2 and PHP5 installer files in a directory and update the msi file names in the following commands.
To have PHP installer find Apache2, do not forget APACHEDIR!
msiexec /i apache_2.2.11-win32-x86-no_ssl.msi /passive ALLUSERS=1 SERVERADMIN=admin@localhost SERVERNAME=localhost SERVERDOMAIN=localhost SERVERPORT=80 INSTALLDIR=c:\apache
msiexec /i php-5.2.10-win32-installer.msi /qn APACHEDIR=c:\apache INSTALLDIR=c:\php ADDLOCAL=ext_php_mssql,apache22
net stop "Apache2.2"
net start "Apache2.2"
CP (2009-04-16 11:27:44)
This is old news to some. But people with Apache 2.0.55 / PHP 5.1.2 might like a reminder before they pull their hair out! (Some of us have ISPs using older version and need to test on a like version before we upload.)
If using PHP 5.1.2, to run Apache as a module, do *not* use Stephan's "php5apache2.dll" from http://www.ApacheLounge.com. That is for pre-5.1.2!
**There is a "php5apache2.dll" included with Windows PHP 5.1.2 zip file by default.**
If you forget this and overwrite the included DLL with Stephan's (as I did) you'll spend hours attempting to escape "DLL hell", with no success.
Anonymous (2009-02-26 06:32:07)
i followed henke37's way to for the httpd.conf
I added all this at the very end of httpd.conf
# For PHP 5
#load the php main library to avoid dll hell
Loadfile "C:\php-5.2.8-Win32\php5ts.dll"
#load the sapi so that apache can use php
LoadModule php5_module "C:\php-5.2.8-Win32\php5apache2_2.dll"
#set the php.ini location so that you don't have to waste time guessing where it is
PHPIniDir "C:\php-5.2.8-Win32"
#Hook the php file extensions
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
Also i didn't use short open tags as they are disabled in
"php.ini-recommended" if you don't change anything
So use this to test
<?php
phpinfo();
?>
NOT
<? phpinfo(); ?> short open tags
added my php directory to the PATH system variable and i start apache manually not as a service
It works for me hope it helps you!
cormac at kernan dot eu (2008-04-20 18:08:21)
All good advice from henke, except where it says "Do not edit the system path". You will NOT be able to load extensions that have dependencies e.g. MySQL, without adding PHP to your system path. This threw me for some time as other extensions without dependencies will work without this requirement.
cfoesterle at yahoo dot com (2008-02-10 08:41:20)
I do not have IIS installed on my server, only Apache. So I had to edit the PHP.ini file and comment out (add leading ";") to the following line "extension=php_iisfunc.dll" as I was getting "Faulting application httpd.exe, faulting module php_iisfunc.dll" errors when this line was active. I also added an additional "AddType application/x-httpd-php .html" to my httpd.conf file so that inline php would work with files ending with an extension of ".html" on my server.
mjm at alum dot mit dot edu (2008-01-26 20:33:00)
If you use the PHP 5 installer, you'll notice that it uses the wrong type of slash on Windows!
Change C:/Program Files/PHP/" to C:\Program Files\PHP\" and everything works great!
packard_bell_nec at hotmail dot com (2007-10-02 20:24:12)
If you install PHP as an Apache CGI binary, you can add:
AddHandler cgi-script .php
into Apache httpd.conf, and add shebang line to every PHP scripts like:
#!php
<?php
phpinfo();
?>
. But adding shebang line has a disadvantage that if you decided to install PHP as an Apache module afterwards, then the shebang line WILL appear in the web page.
In fact, you do NOT need to add shebang line to every PHP script even if you install PHP as an Apache CGI binary, because you can add:
ScriptInterpreterSource Registry-Strict
into Apache httpd.conf, and make the registry file and merge it like:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.php\Shell\ExecCGI\Command]
@="\"C:\\Program Files\\PHP\\php-cgi.exe\""
. Then you will NOT need to change the PHP scripts which do not contain shebang line.
philippeboucher at newlogiccanada dot com dot com (2007-07-31 14:05:20)
To do a silent install of PHP wich correctly modify the httpd.conf file, you HAVE (I find no other way) to put the directory of the Apache inside the INSTALLDIR's MSI option. the APACHEDIR doesn't seem to work. That's the only way I've make it work. Maybe it's because my Apache is not in the default directory, I don't know, but there is a solution for people who cannot make work the silent install (for those who are told by the php setup that it cannot find the httpd.conf file).
Hope it helps someone.
anonymousness (2007-06-15 07:30:26)
Verrrrrrrry important note:
If you enable multi-byte strings for your installation of PHP, the extension loaded MUST be the first extension in the list.
Apache, NOR PHP will generate any error messages or warning information in the error log or in system logs about this.
This information needs to be included in the Readme or in the distributed INI files.
The recommended PHP ini's should place extension=php_mbstring.dll at the top of the list of extensions.
I had completely forgotten about this when recently upgrading php on a test server; and almost set out to re-install apache.
charlie at oblivion dot cz (2007-02-14 16:19:53)
..try to set the extension_dir in php.ini to the absolute path.. (when you are pretty sure that you have set the PHPIniDir the right way)
Jim Keller (2007-01-10 17:35:00)
it's important to note that on Apache 2.2.3 (probably other 2.x versions as well) on Windows, the PHPIniDir directive must use forward slashes to delimit directories, not the backslashes commonly used for Windows path strings. If PHP seems to be ignoring the directive, this may be why.
pcdinh at phpvietnam dot net (2006-10-07 03:50:27)
PHP 6 is under active development but for those whose want to try out the new features or just want to keep updated with the development progress of PHP 6.0, you can follow my instructions below to install it on Windows XP and Apache 2.2.3
# For PHP 6 do something like this:
LoadModule php5_module "c:/server/php6/php6apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "c:/server/php6"
You should change the path as in your system. The directive LoadModule php5_module seems a bit strange to you. It should be LoadModule php6_module instead. However, I have just taken a look at php.internals and came across a message that said it should be changed in the near future after the PHP 5.2 is official released. At the time I write this, PHP 5.2 RC6 is planned to be released in the next few days.
subajawa at yahoo dot com (2006-08-04 13:56:19)
To install PHP as Apache 2 CGI script, add these lines in addition to the 3 lines mentioned in the document.
<Directory "C:/php">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
Isaac dot Brown at ArvinMeritor dot com (2005-05-17 05:59:14)
Some XP machines are having troubles with the PHPIniDir derective not finding the php.ini (or so they think). Directories that do contain a php.ini file are returned as empty and it defaults to the next method of finding php.ini (often C:/windows or C:/winnt).
This is likely caused by read permissions not being set correctly on NTFS file systems, however, it has occurred when no cause could be identified. If setting correct file permissions doesn't work, the easiest way around this problem is moving php.ini to the Apache directory or adding the HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath string to your registry and setting it to the correct directory.