Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
914 views
in Technique[技术] by (71.8m points)

command line interface - How to change the path to php.ini in PHP CLI version

The php that run on the webserver and the CLI version is not using the same php.ini file. If I do a command php --ini, it show this

Configuration File (php.ini) Path: C:Windows
Loaded Configuration File:         C:wampinphpphp5.3.8php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

while my web version uses the php.ini in C:wampinapacheApache2.2.21inphp.ini. This is probably very common for people using wamp.

How do I change the Loaded Configuration File to read from C:wampinapacheApache2.2.21inphp.ini so I don't have to maintain 2 different php.ini versions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Per http://php.net/configuration.file:

php.ini is searched for in these locations (in order):

  • SAPI module specific location (PHPIniDir directive in Apache 2, -c command line option in CGI and CLI, php_ini parameter in NSAPI, PHP_INI_PATH environment variable in THTTPD)
  • The PHPRC environment variable. Before PHP 5.2.0, this was checked after the registry key mentioned below.
  • As of PHP 5.2.0, the location of the php.ini file can be set for different versions of PHP. The following registry keys are examined in order:
    • [HKEY_LOCAL_MACHINESOFTWAREPHPx.y.z], [HKEY_LOCAL_MACHINESOFTWAREPHPx.y] and [HKEY_LOCAL_MACHINESOFTWAREPHPx], where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
    • [HKEY_LOCAL_MACHINESOFTWAREPHP], value of IniFilePath (Windows only).
  • Current working directory (except CLI).
  • The web server's directory (for SAPI modules), or directory of PHP (otherwise in Windows).
  • Windows directory (C:windows or C:winnt) (for Windows), or --with-config-file-path compile time option.

For CLI, your best bet is probably either to set the $PHPRC environment variable for the account that will be executing scripts, or recompile PHP with a different --with-config-file-path configuration setting.

You can also override the php.ini search dir on a per-execution basis by specifying the -c option when invoking PHP:

> php --help
Usage: php [options] [-f]  [--] [args...]
...
  -c | Look for php.ini file in this directory


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...