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

21,082

Solution 1

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

SOLVED:
needed to tell Apache to load the wanted php.ini file

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

HOW in short :
shell 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.ini is the right one either using the php-cli in commandline or phpinfo() :

/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

Solution 2

I think you're missing the quotes:

date.timezone = "Europe/Berlin"

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

Share:
21,082
hornetbzz
Author by

hornetbzz

Old timer but IT brand noob :-) Learning by doing : HTML, CSS, PHP, javascript, C++, Java, Debian admin (shell bash and perl scripting), trac/svn, eclipse helios pdt ... I installed a LAN complete network and scripted a complex website from scratch in my room as I had no idea about frameworks, IDE or existing librairies... ;-) Yes it's allowed to laugh loudly ! Now it will go better thx to stackoverflow members !

Updated on July 09, 2022

Comments

  • hornetbzz
    hornetbzz almost 2 years

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

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

    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 code : Ok

    date_default_timezone_set('Europe/Berlin');
    

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

    date.timezone = 'Europe/Berlin'
    

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

    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.

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

     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 :

     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...

  • Ifedi Okonkwo
    Ifedi Okonkwo over 9 years
    Not true! The php.ini directive date.timezone expects a string alright, but the quotes are NOT required. That's unlike the runtime alternative : date_default_timezone_set('Europe/Berlin'); which (being right within php code) does require the quotes. Just setting thing right! ;)
  • redreinard
    redreinard over 9 years
    It'd be good to point out that for the shell variable it expects a directory, but the apache config wants the path to the actual ini i think.