Change PHP timezone for desired domain
Posted: Tue Feb 21, 2023 4:10 pm
First create test.php script to see what current time will be displayed for example.com domain:
Now open it via browser:
It should show the current hour and minute.
If hour is wrong, then we need to tweak timezone for this domain.
Based on the tutorial for PHP-FPM pool.d conf files - viewtopic.php?f=18&t=54 - we need to do the following.
First, check what PHP version you are running on the example.com domain.
In your SSH run:
The output will be, for example:
Now we know the location of our PHP-FPM pool.d conf, it's: /etc/php/8.0/fpm/pool.d/example.com.conf
Let's edit your PHP-FPM pool.d conf:
Find the last line that begins with php_admin_flag
After that line, add:
Press F2 on your keyboard and confirm saving.
Press ESC twice on your keyboard to exit the editor.
In the end, restart your PHP-FPM by running:
(NOTE: it may be some other PHP version, depending on what PHP version your domain is using)
Code: Select all
sudo cat <<EOF >/home/SOMEUSER/web/EXAMPLE.COM/public_html/test.php
<?php
echo date('H:i');
EOF
Code: Select all
http://example.com/test.php
If hour is wrong, then we need to tweak timezone for this domain.
Based on the tutorial for PHP-FPM pool.d conf files - viewtopic.php?f=18&t=54 - we need to do the following.
First, check what PHP version you are running on the example.com domain.
In your SSH run:
Code: Select all
sudo /usr/local/vesta/bin/v-get-php-version-of-domain example.com
Code: Select all
8.0
Let's edit your PHP-FPM pool.d conf:
Code: Select all
sudo mcedit /etc/php/8.0/fpm/pool.d/example.com.conf
After that line, add:
Code: Select all
php_admin_value[date.timezone] = Europe/Berlin
Press ESC twice on your keyboard to exit the editor.
In the end, restart your PHP-FPM by running:
Code: Select all
sudo systemctl restart php8.0-fpm