php5.3.3 date.timezone 再次未考虑 php.ini 指令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6433721/
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-26 00:23:04  来源:igfitidea点击:

php5.3.3 date.timezone again php.ini directive not taken into account

datetimezonephp

提问by hornetbzz

System: Debian Lenny/Apache 2.2/php5.3.3 compiled from sources

系统:Debian Lenny/Apache 2.2/php5.3.3 源码编译

I'm strugglying with the date.timezone within php.ini.

我正在努力处理 php.ini 中的 date.timezone。

I can define the TZ using in the php source code but I'd like to fix that at once in the ini file.

我可以在 php 源代码中定义 TZ,但我想在 ini 文件中立即修复它。

php code: Ok

php代码:好的

date_default_timezone_set('Europe/Berlin');

php.ini: Not taken into consideration if not setup within the source code

php.ini: 如果未在源代码中设置,则不考虑

date.timezone = 'Europe/Berlin'

I also checked that I modified the right php.inifile and have interference with some php.default.inifiles.
I checked within the apache config files whether there would be an interfering TZ env data, but none.

我还检查了我修改了正确的php.ini文件并干扰了一些php.default.ini文件。
我在 apache 配置文件中检查了是否会有干扰的 TZ env 数据,但没有。

Don't know what to do more, so any hints will be welcomed,

不知道该怎么做,所以任何提示都会受到欢迎,

thx in advance.

提前谢谢。

EDIT: I also tried with no or single or double quotes as date.timezone = 'Europe/Berlin' but I still get a "no value" in the phpinfo.

编辑:我也尝试不使用单引号或双引号作为 date.timezone = 'Europe/Berlin' 但我仍然在 phpinfo 中得到“无值”。

EDIT2: Both phpinfo()and the below test script return that the date.timezone is empty (eg. no value) :

EDIT2:phpinfo()和下面的测试脚本都返回 date.timezone 为空(例如,没有值):

 date_default_timezone_set('America/Los_Angeles');
 $script_tz = date_default_timezone_get();
 $iniset = ini_get('date.timezone') ;
 if (strcmp($script_tz, $iniset)){
   echo "Script timezone ($script_tz) differs from ini-set timezone ($initset).";
 } else {
   echo "Script timezone ($script_tz) and ini-set timezone match.";
 }

EDIT3: hum, I guess I found sthg in the php.ini:

EDIT3,我想我在php.ini 中找到了 sthg :

 Configuration File (php.ini) Path : /usr/local/php533/php.ini 
 Loaded Configuration File : VOID !

So I have to find the way to make sure Apache is looking for the right php.ini somehow...

所以我必须找到确保 Apache 以某种方式寻找正确的 php.ini 的方法......

采纳答案by hornetbzz

Hope it can help others on debian's like distros :

希望它可以帮助 debian 等发行版上的其他人:

SOLVED:
needed to tell Apache to load the wanted php.inifile

已解决:
需要告诉 Apache 加载所需的php.ini文件

Context:
PHP loaded as an Apache module (eg DSO)

上下文:
作为 Apache 模块加载的 PHP(例如 DSO)

HOW in short :
shell ENV

简而言之:
外壳 ENV

PHP_INI_SCAN_DIR=/pathtophpini
export PHP_INI_SCAN_DIR

http.conf

配置文件

# ...
# DSO Modules: PHP as an Apache module
SetEnv PHPRC /usr/pathtophpini
SetEnv PHP_INI_SCAN_DIR /usr/pathtophpini

LoadModule php5_module /pathtophpmod/libphp5.so
PHPINIDir /pathtophpini
# ...

Shell

贝壳

/etc/init.d/apache2 restart   

Now just checking that the loaded configuration file php.iniis the right one either using the php-cli in commandline or phpinfo() :

现在只需使用命令行中的 php-cli 或 phpinfo()检查加载的配置文件php.ini是否正确:

/path/to/your/phpcli/bin/php -i | grep php.ini | tail -n2   
# which gives you the expected answer
Configuration File (php.ini) Path => /pathtophpini/php.ini
Additional .ini files parsed => /pathtophpini/php.ini

Some more documentation :
on that very particular point, provided there are very few docs on that subject, as this is a kind of shared responsability topic between apache and php matters :
on stackoverflow
on php manual
askapache

更多文档:
在那个非常特殊的点上,前提是关于该主题的文档很少,因为这是 apache 和 php 事务之间的一种共享责任主题:关于 php 手册askapache
上的 stackoverflow

回答by tplaner

I think you're missing the quotes:

我认为您缺少引号:

date.timezone = "Europe/Berlin"

The value is a string according to: ini.date.timezone on PHP.netwhich must be wrapped in quotes.

该值是一个字符串,根据PHP.net上的ini.date.timezone必须用引号括起来。