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

标签 php

我正在尝试学习“需要”在命令行/终端中使用 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/

相关文章:

php - 在 PHP 中创建一次性使用的安全 token 的最佳方法是什么?

PHP 构建/集成工具 : Do you use them?

php - Laravel 5 Eloquent 字符集 utf8 问题

java - Json/Java 新手 - 这是什么数据类型?约会时间? 13 位长。使用 PHP

php - 数据图像 base 64

php - SQL添加列名关键字

php - 数据映射器和 zend 框架

javascript - Dropzone.js 显示存储的图像

php - Mailjet剥离<style>标签,应用其自己的内联样式

php - 是否可以在C程序中调用PHP的C函数?