更改 php.ini 位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10386188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:04:23  来源:igfitidea点击:

Change php.ini location

macososx-snow-leopardphphomebrew

提问by Zendy

Is it possible to change the location of php.inito be used by Apache? When I did php -i | grep 'Configuration File', the result is:

是否可以更改php.iniApache 使用的位置?当我这样做时php -i | grep 'Configuration File',结果是:

Path => /usr/local/etc

Loaded Configuration File => /usr/local/etc/php.ini

路径 => /usr/local/etc

加载的配置文件 => /usr/local/etc/php.ini

But the result of phpinfo()is

但结果phpinfo()

Configuration File (php.ini) Path : /etc

配置文件(php.ini)路径:/etc

I can copy over php.inifrom /usr/local/etc/to /etc/, but is it possible to change the php.ini folder?

我可以php.ini/usr/local/etc/to复制过来/etc/,但是可以更改 php.ini 文件夹吗?

I installed PHP using homebrew and I am using OS X Snow Leopard.

我使用自制软件安装了 PHP,我使用的是 OS X Snow Leopard。

采纳答案by webbiedave

PHP uses different .inifiles when running via command line vs running as a web server module. When you grep the results of php -iyour getting the command line ini. It's good practice to have separate ini's for the two environments.

PHP.ini在通过命令行运行与作为 Web 服务器模块运行时使用不同的文件。当您 grepphp -i获取命令行 ini的结果时。为这两个环境设置单独的 ini 是一种很好的做法。

If you must change the directory PHP looks for the php.inifile, you can use the PHPIniDirin your web server conf file.

如果您必须更改 PHP 查找php.ini文件的目录,您可以PHPIniDir在您的 Web 服务器 conf 文件中使用。

If you wish to just add additional directories to be scanned, you can set the PHP_INI_SCAN_DIRenvironment variable.

如果您只想添加要扫描的其他目录,您可以设置PHP_INI_SCAN_DIR环境变量。

回答by Ganesh Patil

To Change php.ini file path we have to declare PHPINIDir in the apache configuration file 'httpd.conf' syntax for that is :

要更改 php.ini 文件路径,我们必须在 apache 配置文件“httpd.conf”中声明 PHPINIDir 语法为:

PHPINIDir "path_to_ini_file";