简体   繁体   中英

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

I have IIS 7.0 and two versions PHP v5 and v7 on my Microsoft Windows Server 2008 Standard 6.0 SP2. The problem is, that PHP7 or IIS tries to use the php.ini of PHP5 for IIS "websites".

So on the command line everything is fine:

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)

But in the IIS Manager and in the phpinfo() output not:

IIS的网站 -  PHP设定

的phpinfo版本,SAPI-PHP-INI

I think, it's a PHP ( cgi-fcgi SAPI) issue, not an IIS issue (but not sure).

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


Also tried it over the Registry, but that didn't help:

注册表-PHP-IniFilePath

The solution of Jan Reilink seems also correct, but unfortunately I could not find out, how to apply it the right way (see this and other my comments below Jan's answer).

Finally I got it solved over the IIS GUI:

IIS GUI  - > FastCGI设置

And then FastCGI Settings -> EnvironmentVariables -> PHPRC :

IIS的FastCGI的 - 设置 -  EnvironmentVariables-PHPRC

See also " Configure IIS to Handle PHP Requests " in the chapter "Using FastCGI to Host PHP Applications on IIS 7" of the IIS documentation.

You need to set environment variables in your FastCgi configuration to host multiple PHP versions in IIS. The one you want is 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

(note the -c argument as well)

and do the same for PHP 7, and change the path. I have this, and more, explained in my blog post https://www.saotn.org/php-wincache-on-iis/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM