如何在PHP CLI版本中将路径更改为php.ini [英] How to change the path to php.ini in PHP CLI version

查看:440
本文介绍了如何在PHP CLI版本中将路径更改为php.ini的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网络服务器上运行的php和CLI版本未使用相同的php.ini文件.如果我执行命令php --ini,它会显示

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:\wamp\bin\php\php5.3.8\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

而我的网络版本使用C:\wamp\bin\apache\Apache2.2.21\bin\php.ini中的php.ini.这对于使用湿巾的人来说很常见.

while my web version uses the php.ini in C:\wamp\bin\apache\Apache2.2.21\bin\php.ini. This is probably very common for people using wamp.

如何更改已加载的配置文件以从C:\wamp\bin\apache\Apache2.2.21\bin\php.ini读取,这样我就不必维护2个不同的php.ini版本?

How do I change the Loaded Configuration File to read from C:\wamp\bin\apache\Apache2.2.21\bin\php.ini so I don't have to maintain 2 different php.ini versions?

推荐答案

每个 http://php.net/configuration .file :

在以下位置搜索

php.ini(按顺序):

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

  • SAPI模块的特定位置(Apache 2中的PHPIniDir指令,CGI和CLI中的-c命令行选项,NSAPI中的php_ini参数,THTTPD中的PHP_INI_PATH环境变量)
  • PHPRC环境变量.在PHP 5.2.0之前,这是在下面提到的注册表项之后进行检查的.
  • 从PHP 5.2.0开始,可以为不同版本的PHP设置php.ini文件的位置.按顺序检查以下注册表项:
    • [HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ x.y.z],[HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ x.y]和[HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP \ x],其中x,y和z表示PHP主要,次要和发行版本.如果这些键中的任何一个都有IniFilePath的值,则找到的第一个键将用作php.ini的位置(仅Windows).
    • [HKEY_LOCAL_MACHINE \ SOFTWARE \ PHP],IniFilePath的值(仅Windows).
    • 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_MACHINE\SOFTWARE\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], 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_MACHINE\SOFTWARE\PHP], value of IniFilePath (Windows only).

      对于CLI,最好的选择是为将要执行脚本的帐户设置$PHPRC环境变量,或者使用其他--with-config-file-path配置设置重新编译PHP.

      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.

      您还可以通过在调用PHP时指定-c选项来逐执行覆盖php.ini搜索目录:

      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
      
      

      这篇关于如何在PHP CLI版本中将路径更改为php.ini的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆