Adapt timezones on Heroku
I'm using the dynos of Heroku and the Postgres database addon from Heroku. Both are on UTC by default and Heroku is specifically advising against changing it. So make sure you know the repercussions.
Dynos
For the dynos you can simple use an environment variable called TZ
and set it to your timezone, for example: Europe/Berlin
.
Postgres
For Postgres there isn't one specific instance. The database within Postres has it's own setting. You can see the current timezone for the database with:
SHOW TIMEZONE;
which should result in Etc/UTC
.
You can set it through heroku pg:psql
and running the following SQL:
ALTER DATABASE your_database_name SET timezone = 'Europe/Berlin';
PHP (or any other application language)
Your application language might also have a timezone defined. For PHP it's also set to UTC in a php.ini file from Heroku. To change it you need to add a custom .user.ini
file with the following content:
date.timezone = 'Europe/Berlin'
Make sure to put the .user.ini
into the directory where php is executed. If you've got normal repository, you don't need to worry about this. If you've got a monorepo (as I do), you might need to have something like this in your Procfile
:
release: heroku/release/release.sh
web: cd api && vendor/bin/heroku-php-apache2
So my Symfony application lives in /api
and therefore I need to swich to the directory before triggering vendor/bin/heroku-php-apache2
. And therefore the .user.ini
file needs to be in /api/.user.ini
.