Jump to content

Timezone for cron is different to timezone in dashboard


Recommended Posts

Hi,

I know this has been asked before but my situation seems slightly different.

My cron runs under a custom location: 

 /home/user/crons/

Naturally my cron is configured to get it's configuation from:

/home/user/public_html/whmcs/configuration.php

I have created a manul php.ini in my whmcs directory and set the timezone to my local time zone.
Upon checking my timezone in the admin dashboard under Utilities -> System - PHP Info

I can see that my local timezone is set correctly:
See snapshot attached.

However, my cron is still running at UTC instead of UTC+2

So I ran the following command in the terminal and retrieved the php.ini file location that the crons are running under:

php -i | grep "Loaded Configuration File"

and the following server file was retrieved which shows UTC and not UTC+2:

/opt/alt/php72/etc/php.ini

I don't have access to this file obviously as it is managed by root.

So I cat'd this file to check the timezone:

[user@server crons]$ cat /opt/alt/php72/etc/php.ini |grep date.
; Defines the default timezone used by the date functions
date.timezone = "UTC"
;date.default_latitude = 31.7667
;date.default_longitude = 35.2333
;date.sunrise_zenith = 90.583333
;date.sunset_zenith = 90.583333
; Check HTTP Referer to invalidate externally stored URLs containing ids.
; Specify how datetime and datetim4 columns are returned
;mssql.datetimeconvert = On
[user@server crons]$

My dashboard is running the local php.ini file that I created so that is set correct but my crons are running incorrectly at UTC

So how do I get my crons to run at UTC+2 as i do not have access to the server file.

timezone.png

Link to comment
Share on other sites

Using php.ini locally is a bad idea. Instead, use configuration files, which is what they're there for, to set variables like this

In this case, use something like

date_default_timezone_set('America/Chicago');

Adjust that to your needs, but this will tell WHMCS what your proper date is

Bonus:
If you move servers, you don't have to worry about php.ini being not allowed (many hosts don't allow that)

Link to comment
Share on other sites

Could you give me more documentation around what you mean by "configuration files"?
I of course have a configuration file in my whmcs root but my cron runs in a custom location for security reasons and refers to my whmcs root configuration file.

but that configuration file doesn't specify the date.timezone as I haven't found any documentation on the WHMCS knowledgebase about setting it there.

If you're referring to PHP configuration files then whats the difference between a php.ini file that I manually create and the config file that you are referring to??  I am a little lost at what YOU mean by configuration file...

 

Edited by bluesteam
Link to comment
Share on other sites

18 hours ago, bluesteam said:

but that configuration file doesn't specify the date.timezone as I haven't found any documentation on the WHMCS knowledgebase about setting it there.

i've used it for years - I think years ago it was mentioned in the docs, not sure if it is anymore...

Link to comment
Share on other sites

I DELETED the manually created php.ini file in my whmcs root directory.

Then I removed all php directives out of the htaccess file that was added to the htaccess file by the 'MultiPHP Ini Editor'.

I rechecked my timezone in Utilities -> System -> PHP info and it was now set back to UTC.

I then added the line date_default_timezone_set('Africa/Johannesburg'); to my WHMCS configuration.php file and rechecked the timezone.

It is still set to UTC.  so what am I doing wrong?

Link to comment
Share on other sites

1 minute ago, brian! said:

your best bet might be to have a word with your host as it sounds more a server configuration issue than anything to do directly with WHMCS.

Well,  Thats just it, they are just going to tell me to use a manual php.ini file or set it in the .htaccess file which I will gladly do if I knew it was also going to apply to the cron in a custom location.  But it's doesn't

I know it's working for you but I haven't found it anywhere in the WHMCS documentation that this method works or is even supported.

 

Link to comment
Share on other sites

2 hours ago, bluesteam said:

Then I removed all php directives out of the htaccess file that was added to the htaccess file by the 'MultiPHP Ini Editor'.

I'm sure you're aware, but that will set your account to use whatever the default PHP version is, potentially downgrading the version you're on.

Link to comment
Share on other sites

24 minutes ago, bluesteam said:

I know it's working for you but I haven't found it anywhere in the WHMCS documentation that this method works or is even supported.

it's supported for setting a timezone...

there are similar posts later than 2010 and upto this year by others...

Link to comment
Share on other sites

5 minutes ago, bear said:

I'm sure you're aware, but that will set your account to use whatever the default PHP version is, potentially downgrading the version you're on.

The PHP directives were applied for the specific PHP version i am using specifying in the IfModule.  So this isn't an issue.

These are what I removed:

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 600
   php_value max_input_time 600
   php_value max_input_vars 5000
   php_value memory_limit 512M
   php_value post_max_size 128M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php72"
   php_value upload_max_filesize 64M
   php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors Off
   php_value max_execution_time 600
   php_value max_input_time 600
   php_value max_input_vars 5000
   php_value memory_limit 512M
   php_value post_max_size 128M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php72"
   php_value upload_max_filesize 64M
   php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit

 

7 minutes ago, brian! said:

it's supported for setting a timezone...

there are similar posts later than 2010 and upto this year by others...

I'm not saying it's not supported.  simply that not finding it in actual documentation makes me question whether this is supported.  but looking at those posts, the instruction came from WHMCS staff so it must be supported.

Anyways, I'm now stuck because the host just says to use a php.ini file and WHMCS doesn't apply the php.ini to the custom cron location. 😞

Link to comment
Share on other sites

12 minutes ago, bluesteam said:

I'm not saying it's not supported.  simply that not finding it in actual documentation makes me question whether this is supported.  but looking at those posts, the instruction came from WHMCS staff so it must be supported.

it was in the docs until towards the end of Sept 2014, then it got updated to using php.ini

https://web.archive.org/web/20140822173118/https://docs.whmcs.com/Changing_Timezone

VHpVYUU.png

Link to comment
Share on other sites

thank Brian.  The fact that when I apply it in my configuration.php file it doesn't work, tells me that maybe the reason this method was abandoned was probably because on some environments (like mine) it doesn't work.  so they resorted to the php.ini method.

I am wondering if I place a php.ini in my custom cron location if the cron would use the settings from that php.ini??

Link to comment
Share on other sites

UPDATE: I found this morning that EVEN THOUGH the PHP info is showing UTC timzone in Utilities -> System -> PHP Info the cron is now running on the right time.

Looking at the timezone in PHP Info, I was looking at the Directive section and not the Date section which now DOES show the correct timezone.   So this flag date_default_timezone_set('Africa/Johannesburg'); in the configuration file is changing the Date section and the  manual php.ini changes the Directive section.  The cron is configured according to the WHMCS documents which tells us to set the config.php file to point to the configuration.php file in the whmcs root which will take the timezone set in that file.

All is good in the world now 😁 Thanks for everyone's help.

timezone.png.5174af312b359b3df121d17059f9c849.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated