大网数据广告活动
服务器运维问答

How to set date.timezone and what is the correct place to do it

· 52CE 我爱测

(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…

问题原文

原帖链接 · nosh · CC BY-SA 4.0

(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?

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 4.0

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):

  1. 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 (or nginx), having all its permissions.

  2. 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
    }
    
  3. 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-09-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。