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.
Apache 2.x (Microsoft Windows 用)
このセクションでは、Microsoft Windows 上の Apache 2.x で PHP を使用する場合について説明します。 Apache 1.3.x で PHP を使用する場合 については別に記載されています。
注意:
まず始めに、マニュアルインストールの手順 をお読みください。
注意: Apache 2.2 のサポート
Apache 2.2 を利用している方は、Apache 2.2 用の DLL ファイルの名前が php5apache2.dll ではなく php5apache2_2.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 の設定を行ってください。
PHP を Windows 上の Apache 2.x で動かすには三通りの方法があります。 PHP をハンドラとして動かす方法、CGI として動かす方法、そして FastCGI で動かす方法です。
注意: Windows 上で Apache 設定ファイルにパスの値を追加する際、例えば c:\directory\file.ext に含まれるすべてのバックスラッシュは c:/directory/file.ext のように前向きスラッシュに変換する必要があります。 また、ディレクトリを表す際には最後にスラッシュをつけなければなりません。
Apache ハンドラとしてのインストール
以下の行を Apache 設定ファイル httpd.conf に追加して Apache 2.x 用の PHP モジュールを読み込まなければなりません。
例1 PHP を Apache 2.x ハンドラとして使う設定
# LoadModule php5_module "c:/php/php5apache2.dll" AddHandler application/x-httpd-php .php # php.ini へのパスを設定します PHPIniDir "C:/php"
注意: 上の例の C:/php/ は実際のパスにあわせて修正してください。 LoadModule ディレクティブで php5apache2.dll と php5apache2_2.dll のどちらを使うのかに注意し、 指定したファイルが実際にその場所にあるかどうかを忘れずに確認しましょう。
上の設定は、拡張子 .php を含むすべてのファイルを PHP で処理するようにします。 たとえそれ以外の拡張子が含まれていたとしてもです。たとえば example.php.txt という名前のファイルも PHP ハンドラが処理します。ファイル名の 最後が .php であるものだけを処理させたい場合は、次のように設定します。
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
CGI としての PHP の実行
» Apache CGI ドキュメント を読み、Apache 上の CGI について理解しておきましょう。
PHP を CGI として実行するには、ScriptAlias ディレクティブで CGI ディレクトリとして指定した場所に php-cgi ファイルを置かなければなりません。
さらに、PHP ファイルに #! の行を追加して PHP バイナリの場所を指定しなければなりません。
例2 PHP を Apache 2.x 上で CGI として動かす例
#!C:/php/php.exe <?php phpinfo(); ?>
CGI モードで公開したサーバは、いくつかの脆弱性の標的となる可能性があります。 これらの攻撃からサーバを守る方法については、 CGI セキュリティ のセクションを参照してください。
PHP を FastCGI で実行する
PHP を FastCGI で動かすのには、CGI として動かすのにくらべると多くの利点があります。 設定方法は単純明快です。
まず mod_fcgid を » http://httpd.apache.org/mod_fcgid/ から取得します。Win32 用のバイナリがこのサイトからダウンロードできます。 そして、説明に従ってモジュールをインストールしましょう。
次にウェブサーバを以下のように設定します。 パスの部分は適切に変更し、インストールするシステム上の環境にあわせましょう。
例3 PHP を FastCGI として動かす Apache の設定
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
Apache 2.x (Microsoft Windows 用)
16-Jun-2010 01:48
03-Mar-2010 05:48
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
24-Feb-2010 12:53
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.
14-Dec-2009 06:56
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
10-Dec-2009 09:25
If anybody here encounters an error regarding PHPIniDir, change PHPIniDir "C:/php/" to PHPIniDir "C:\php\".
07-Jul-2009 05:08
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"
16-Apr-2009 06:27
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.
26-Feb-2009 02:32
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!
21-Apr-2008 01:08
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.
10-Feb-2008 04:41
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.
27-Jan-2008 04:33
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!
03-Oct-2007 03:24
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.
31-Jul-2007 09:05
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.
15-Jun-2007 02:30
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.
15-Feb-2007 12:19
..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)
11-Jan-2007 01:35
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.
07-Oct-2006 10:50
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.
04-Aug-2006 08:56
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>
17-May-2005 12:59
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.
