How to set date.timezone and what is the correct place to do it
The fpm/conf.d/
is scanned for additional .ini
files, making it easier to separate configuration for example per module. Those are scanned for every FPM pool, i.e. it's a global configuration just like the php.ini
.
You can override individual settings for a single pool in your fpm/pool.d/poolname.conf
:
php_admin_value[date.timezone] = Europe/Berlin
Shortly on PHP FPM pools that allows using separate settings, resources & user (permissions):
-
The default pool is configured in
fpm/pool.d/www.conf
for listening a UNIX socket:listen = /run/php/php7.2-fpm.sock
Also notice that it runs as the user
www-data
(ornginx
), having all its permissions. -
Nginx
server{}
block passes PHP script to this socket for the PHP FPM pool to handle:location ~ \.php$ { fastcgi_pass unix:/run/php/php7.2-fpm.sock; # another fastcgi options }
-
You can run the PHP of your single project as a separated user
mautic
by creating an additional FPM pool, e.g.fpm/pool.d/mautic.conf
for your Mautic project:[mautic] user = mautic group = mautic listen = /run/php/mautic.sock chdir = /var/www/mautic # or /home/mautic etc. listen.owner = www-data # or nginx(?) to let Nginx use the socket listen.group = www-data php_admin_value[date.timezone] = Europe/Berlin
And naturally use this new
/run/php/mautic.sock
in the relevant Nginx configuration.
The official documentation starts from where you should already know the basic idea, making it a bit hard for beginners. Luckily there are tutorials, or you could even enjoy watching a video.
nosh
Updated on September 18, 2022Comments
-
nosh over 1 year
(I'm trying to deploy an open source php project to nginx. The project itself does not matter.)
I need to set date.timezone to my local timezone because the project uses a global setting.
I found a line in my php.ini (at /etc/php/7.0/fpm/php.ini for debian) file but because I did not want to change the global setting, I created a new ini file in the fpm/conf.d/ directory with the line:
date.timezone = ('Europe/Berlin')
This is one of the supported time zones as documented here However when I look at my php info, the timezone reflects in both "Local Value" as well as "Master Value".
Can I have it so that only this one php project has the timezone set while the global remains at the default UTC?
-
nosh over 5 yearsOK, I don't know what a "pool" is in this context. Can you please give me some best practices for deployment/ point me to a web page for these php deployments?
-
Esa Jokinen over 5 yearsThis doesn't answer the question that is specifically about changing the timezone for a single project, leaving others unaffected. In Debian, the path is not
/etc/php.ini
but e.g./etc/php/7.0/fpm/php.ini
, depending on the version and whether you use CLI, FPM etc. -
Esa Jokinen over 5 yearsHaving all the projects run as a single user is not lazy, but careless. One vulnerable old WordPress plugin/theme and the whole server is a cracker playground. Real lazy people like me try to do things properly from the beginning to avoid unnecessary work in the future.
-
nosh over 5 yearsYea, I already said I found the php.ini file and DO NOT want to change the setting globally. I managed to change the setting but only globally because I used the conf.d directory.
-
hgoscenski over 5 yearsMy apologies all, I missed that in the original question and that falls upon my shoulders.