gpt4 book ai didi

php - 将自定义路径设置为 php.ini(不在 Apache 中)

转载 作者:可可西里 更新时间:2023-11-01 13:56:57 25 4
gpt4 key购买 nike

我正在尝试学习“需要”在命令行/终端中使用 php 来完成某些任务的 Symfony。

我喜欢存储我的 php.ini/apache2/conf目录,将所有服务器配置放在一个地方(并且每次更改某些内容时都不必处理 Windows 的 UAC)。在 Apache 中,通过

设置默认的 php.ini 位置是没有问题的
PHPIniDir "C:/apache2/conf"

然而,当从终端运行 php 时——而不是通过 apache 服务器——它默认在 C:\Windows 目录中查找文件,尽管那里没有文件:

C:\>php -i
...
Configuration File (php.ini) Path => C:\Windows
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
...

当然,我可以使用 php -c C:\apache2\conf ... 绕过这个每次我使用它,但我更喜欢更简单和永久的解决方案。

这可能吗?提前致谢!

最佳答案

http://www.php.net/manual/en/configuration.file.php

php.ini is searched 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_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 these keys, then 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).

  • 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

此外,从 PHP 5.3 开始,您可以使用每个目录的 .ini 文件。参见 http://php.net/manual/en/configuration.file.per-user.php

关于php - 将自定义路径设置为 php.ini(不在 Apache 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5046192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com