如何设置要使用的默认 php.ini,OSX Yosemite
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27861720/
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
How to set default php.ini to be used, OSX Yosemite
提问by Brieuc
I set up a new environment using OSX Yosemite.
我使用 OSX Yosemite 设置了一个新环境。
I'm using the built-in PHP.
我正在使用内置的 PHP。
I'd like to change some config in php.ini such as date.timezone but none of the modifications are working despite restarting the apache server (sudo apachectl restart).
我想更改 php.ini 中的一些配置,例如 date.timezone,但尽管重新启动了 apache 服务器(sudo apachectl restart),但所有修改都不起作用。
phpinfo() is giving a different path than php --ini command.
phpinfo() 给出了与 php --ini 命令不同的路径。
phpinfo():
phpinfo():
Configuration File (php.ini) Path /usr/local/php5/lib
Loaded Configuration File /usr/local/php5/lib/php.ini
配置文件(php.ini)路径/usr/local/php5/lib
加载的配置文件 /usr/local/php5/lib/php.ini
Via commands :
通过命令:
which php
/usr/bin/php
php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /Library/Server/Web/Config/php
Additional .ini files parsed: (none)
哪个php
/usr/bin/php
php --ini
配置文件(php.ini)路径:/etc
加载的配置文件:/etc/php.ini
在以下位置扫描其他 .ini 文件:/Library/Server/Web/Config/php
解析的其他 .ini 文件:(无)
So I guess I have to tell somewhere where I should set the default php.ini to be used.
所以我想我必须告诉我应该在哪里设置要使用的默认 php.ini。
Any ideas, hints?
任何想法,提示?
回答by Gergely Havlicsek
move the configuration file to the right spot and update the timezone.
将配置文件移动到正确的位置并更新时区。
$ sudo cp /etc/php.ini.default /etc/php.ini
Open the config file /etc/php.ini, find the line that sets your timezone and update it correspondingly.
打开配置文件/etc/php.ini,找到设置你的时区的那一行并进行相应的更新。
date.timezone = Europe/Berlin
Do not forget to remove the ; at the beginning. Restart the Apache server to have PHP load the new .ini file.
不要忘记删除 ; 一开始。重新启动 Apache 服务器以让 PHP 加载新的 .ini 文件。
sudo apachectl restart
回答by Oskar S.
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)
SAPI 模块特定位置(Apache 2 中的 PHPIniDir 指令,CGI 和 CLI 中的 -c 命令行选项,NSAPI 中的 php_ini 参数,THTTPD 中的 PHP_INI_PATH 环境变量)
http://php.net/manual/en/configuration.file.php
http://php.net/manual/en/configuration.file.php
Try changing PHPIniDir
in httpd.conf
.
尝试改变PHPIniDir
在httpd.conf
。
回答by Elyzium
On mac sierra with php7.1, edit /usr/local/etc/php/7.1/php.ini won't work, you can edit like this:
在带有 php7.1 的 mac sierra 上,编辑 /usr/local/etc/php/7.1/php.ini 不起作用,您可以这样编辑:
1) cp /etc/php.ini.default php.ini
2) edit php.ini to adddate.timezone = Europe/Berlin
1) cp /etc/php.ini.default php.ini
2) 编辑 php.ini 添加date.timezone = Europe/Berlin
then restart your apache,
然后重启你的apache,
回答by aneetkukreja
Short answer: If you're on mac and you have the file /usr/local/php5/php.d/99-liip-developer.ini then edit timezone there and it will effect php-cgi (web-browser)
简短回答:如果你在 mac 上并且你有文件 /usr/local/php5/php.d/99-liip-developer.ini 然后在那里编辑时区,它会影响 php-cgi (web-browser)
Long answer: n mac system for few settings like timezone php.ini file (showing loaded in phpinfo) don't work. Because sometimes we unknowingly install php packaged by Liip. That's why apache picks up few settings from liip-developer.ini config file which is usually located at /usr/local/php5/php.d/99-liip-developer.ini
长答案:n mac 系统对于一些设置,如时区 php.ini 文件(显示在 phpinfo 中加载)不起作用。因为有时候我们在不知不觉中安装了Liip打包的php。这就是为什么 apache 从通常位于 /usr/local/php5/php.d/99-liip-developer.ini 的 liip-developer.ini 配置文件中获取一些设置的原因