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


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:


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

; Defines the default timezone used by the date functions
date.timezone = Europe/London

;date.default_latitude = 31.7667

;date.default_longitude = 35.2333

;date.sunrise_zenith = 90.583333

;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 "" 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)


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.


Pawel Dawczak answers:


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

Best regards.

You can create simple php file, like this:



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=",57039,57090#msg-57090"]]Link 1[[/LINK]] and [[LINK href=""]]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=""]]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

Loaded Configuration File

but the webserver, Nginx, is using:


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:


I have this in the file:


PHP was giving me an error on startup, saying that it could not find the file "". 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.