Ask your Symfony questions! Pay money and get answers fast! (more info)

Symfony and PHP-cli are using different php.ini, trouble with timezone Symfony

  • SOLVED

See the attached screenshot to see the error that I am getting.

I am developing locally on my Mac. I "sudo su" to root, and then, with a text editor, I change:

/private/etc/php.ini

I add in the timezone. This filters though to /etc/php.ini.

I then do "cat /etc/php.ini" and I see this:

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

[CLI Server]
; Whether the CLI web server uses ANSI color coding in its terminal output.
cli_server.color = On

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/London

; http://php.net/date.default-latitude
;date.default_latitude = 31.7667

; http://php.net/date.default-longitude
;date.default_longitude = 35.2333

; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333


So the timezone is set. But I get an error. I have tried both adding and removing quotes around the timezone. It makes no difference.

I am running Nginx and php-fpm. I know this php.ini file is in use since I needed to adjust the path to the "apc.so" extension, and editing this file fixed the problem.

I am joining a team that is working on a Symfony 2.0 project that has been partially upgraded to 2.1 (mostly upgraded in its use of composer.phar).

Any thoughts why I get this error?

ErrorException: Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.


Answers (5)

2013-05-20

anxious answers:

Are you sure you are editing the right php.ini file ?

check via : php --ini , does it output /private/etc/php.ini or something else ?

Also, add double quotes for the value, like "Europe/London" .... even if you have the feeling that it's not changing a thing.

Be sure to restart your webserver after any modification of php.ini


Lawrence Krubner comments:

Restart my webserver? I am running Nginx. The PHP runs as FastCGI. I don't think "restart the web browser" has any meaning here. That would be a useful idea if I was running Apache/mod_php.

2013-05-20

Pawel Dawczak answers:

Hi,

Probably your server uses different php.ini file. You can check which one is used with phpinfo(); like here:

http://screencast.com/t/1QgtZG5EI

Best regards.

You can create simple php file, like this:

<?php

phpinfo();


Put it in your projects web folder, open it with your browser. Then you'll see similar output to screenshot I posted eariler.

This will tell you, which php.ini is loaded by your web server, which may be different for CLI and WebServer.

Hope it helped.

Sorry, I don't have experience with Ngix, but little investigation resulted with:

[[LINK href="http://forum.nginx.org/read.php?3,57039,57090#msg-57090"]]Link 1[[/LINK]] and [[LINK href="http://stackoverflow.com/questions/1215120/set-php-include-path-from-nginx"]]Link2[[/LINK]].

I'm not sure if any of this will help - I don't have such environment to check this, but answers look reasonable.

====

Please check this:

[[LINK href="http://wiki.nginx.org/Symfony"]]link[[/LINK]]


Lawrence Krubner comments:

Maybe it is the php.ini, or maybe it is some internal config. I notice if I do this:

grep -iR "time_zone" exo-service

I get:

exo-service/app/cache/dev/appDevDebugProjectContainer.php: 'time_zone' => 'America/New_York',
exo-service/app/cache/dev/appDevDebugProjectContainer.php: 'time_zone' => 'Europe/London',
exo-service/app/cache/dev/appDevDebugProjectContainer.php: 'time_out_booking.providers.opentable_london.time_zone' => 'Europe/London',
exo-service/app/cache/dev/appDevDebugProjectContainer.php: 'time_out_booking.providers.opentable_ny.time_zone' => 'America/New_York',
exo-service/app/cache/dev/appDevDebugProjectContainer.xml: <parameter key="time_zone">America/New_York</parameter>
exo-service/app/cache/dev/appDevDebugProjectContainer.xml: <parameter key="time_zone">Europe/London</parameter>
exo-service/app/cache/dev/appDevDebugProjectContainer.xml: <parameter key="time_out_booking.providers.opentable_london.time_zone">Europe/London</parameter>
exo-service/app/cache/dev/appDevDebugProjectContainer.xml: <parameter key="time_out_booking.providers.opentable_ny.time_zone">America/New_York</parameter>
exo-service/app/config/config.yml: time_zone: 'America/New_York'
exo-service/app/config/config.yml: time_zone: 'Europe/London'
exo-service/app/config/config_common_dev.yml: time_zone: 'America/New_York'
exo-service/app/config/config_common_dev.yml: time_zone: 'Europe/London'
exo-service/app/config/search_indexer.yml: site_time_zones:
exo-service/src/Hotel_Safari/Bundle/BookingBundle/DependencyInjection/Hotel_SafariBookingExtension.php: $container->setParameter( 'time_out_booking.providers.opentable_london.time_zone', $config[ 'providers' ]['opentable_london']['time_zone'] );
exo-service/src/Hotel_Safari/Bundle/BookingBundle/DependencyInjection/Hotel_SafariBookingExtension.php: $container->setParameter( 'time_out_booking.providers.opentable_ny.time_zone', $config[ 'providers' ]['opentable_ny']['time_zone'] );
exo-service/src/Hotel_Safari/Bundle/BookingBundle/Provider/Handler/OpenTableHandler.php: $dateTimeZone = !empty( $config[ 'time_zone' ] ) ? $config[ 'time_zone' ]: \date_default_timezone_get();
exo-service/src/Hotel_Safari/Bundle/BookingBundle/Resources/config/services.xml: <argument type="string" id="timeZone">%time_out_booking.providers.opentable_london.time_zone%</argument>
exo-service/src/Hotel_Safari/Bundle/BookingBundle/Resources/config/services.xml: <argument type="string" id="timeZone">%time_out_booking.providers.opentable_ny.time_zone%</argument>
exo-service/src/Hotel_Safari/Bundle/SearchIndexerBundle/DependencyInjection/Configuration.php: ->arrayNode('site_time_zones')
exo-service/src/Hotel_Safari/Bundle/SearchIndexerBundle/DependencyInjection/Hotel_SafariSearchIndexerExtension.php: \array_map(function ($m) { return $m['site']; }, $config['site_time_zones']),
exo-service/src/Hotel_Safari/Bundle/SearchIndexerBundle/DependencyInjection/Hotel_SafariSearchIndexerExtension.php: \array_map(function ($m) { return $m['timezone']; }, $config['site_time_zones']));


Lawrence Krubner comments:

This is a headache if true:

Configuration File (php.ini) Path
/usr/local/etc/php/5.4

Loaded Configuration File
/usr/local/etc/php/5.4/php.ini


but the webserver, Nginx, is using:

/etc/php.ini

How do I get Symfony to use the same php.ini as Nginx?


Lawrence Krubner comments:

Sorry, I should re-phrase that. Nginx has no awareness of PHP. But PHP on the command line, and at startup, is using this file:

/etc/php.ini

I have this in the file:

extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/apc.so

extension=memcache.so


PHP was giving me an error on startup, saying that it could not find the file "apc.so". So I had to specify the path. And then the error went away. So PHP on the command line is certainly drawing from this file. I was able to adjust this file and see the results right away.

But Symfony is using a different PHP config. Anyway to get them to use the same php.ini file?

I suppose I could edit both php.ini files, but that seems fragile, like a disaster waiting to happen.




Lawrence Krubner comments:

Uploading screenshot.