3

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

3

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.

| improve this answer | |
  • OK, 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? – Nosh Sep 10 '18 at 13:50
0

Honestly, I am lazy and simply set it in /etc/php.ini. This covers all of the php applications on the server and in most cases all of the applications on the server will be in the same TZ.

Simply open /etc/php.ini and them find the line with date.timezone and use whatever your required timezone is. For a list of possible timezones see the official PHP doc.

| improve this answer | |
  • 1
    This 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 Sep 11 '18 at 9:51
  • Having 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. – Esa Jokinen Sep 11 '18 at 9:53
  • Yea, 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. – Nosh Sep 11 '18 at 10:09
  • My apologies all, I missed that in the original question and that falls upon my shoulders. – hgoscenski Sep 11 '18 at 18:06
0

Side note here

In the situation where your're developing using Laravel, in the config/app.php file you can specify timezone only of that project.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.