如何在 Windows Server 2008 r2 上为 PHP CGI/FastCGI SAPI 设置 php.ini 路径?

How to set the php.ini path for PHP CGI/FastCGI SAPI on Windows Server 2008 r2?

我的 Microsoft Windows Server 2008 Standard 6.0 SP2 上有 IIS 7.0 和两个版本 PHP v5v7。问题是,PHP7 或 IIS 试图将 PHP5 的 php.ini 用于 IIS "websites".

所以在命令行上一切正常:

X:\>php -v
PHP 7.0.2 (cli) (built: Jan  6 2016 12:59:59) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

X:\>php --ini
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File:         D:\Data\Programme\php7\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

但在 IIS 管理器和 phpinfo() 中输出不是:

我认为,这是一个 PHP (cgi-fcgi SAPI) 问题,不是 IIS 问题(但不确定)。

如何在 Windows Server 2008 上为 PHP CGI/FastCGI SAPI 设置正确的 php.ini


也通过注册表尝试过,但没有帮助:

您需要在 FastCgi 配置中设置环境变量以在 IIS 中托管多个 PHP 版本。你要的是 PHPRC:

AppCmd set config -section:system.webServer/fastCgi
  /+"[fullPath='c:\php5\php-cgi.exe', arguments='-c
  c:\php5\php.ini'].environmentVariables.
  [name='PHPRC',value='c:\php5\php.ini']" /commit:apphost

(还要注意 -c 参数)

并为PHP 7 做同样的事情,并更改路径。我有这个,还有更多,在我的博客 post https://www.saotn.org/php-wincache-on-iis/.

中解释

of Jan Reilink seems also correct, but unfortunately I could not find out, how to apply it the right way (see 和我在 Jan 的回答下面的其他评论)。

最后我通过 IIS GUI 解决了这个问题:

然后FastCGI Settings -> EnvironmentVariables -> PHPRC

另请参阅 IIS 文档 "Using FastCGI to Host PHP Applications on IIS 7" 章中的“Configure IIS to Handle PHP Requests”。