First off I must say that I am not very knowledgeable when it comes to linux, but I played with it enough over the past year to be semi-comfortable with it. I am renting a dedicated web server which is running centos with xen virtualization that has centos installed on the vm. I do not have access to the parent server, I can only manipulate the vm, of which I have full control. Everything is setup exactly as I want it except for the time/timezone. I am running a php/mysql website and I need the timezone to be set to UTC or GMT because I am doing calculations in the website to figure out proper time/timezone based on a users selected city.
What I know:
I am able to properly set the timezone by using the following command:
sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime
Once this command is run, I can use the 'date' command and it will show me the proper date/time/timezone. At this time if I look at the time in a php script, it will not be the right date/time/timezone. It took me quite a while to figure out that to get php to see the timezone change, I had to reboot the whole server, and only then will the timezone be set properly on my website (I believe at one point I tried only resetting the apache service and that didn't help).
I am not sure if there is some sort of trigger whether time based or not, but sometime after a week or so, the timezone is reset to whatever I specify in my whm install under "Server Configuration" > "Server Time". This reset happens seemingly automatically and without warning. I just notice that the time on my website is off by hours and the timezone is not UTC any longer. Unfortunately utc or gmt timezone are not valid options in the whm configuration even though I have read that they used to be at some point. What is interesting to me is that somehow the time and timezone are being reset and noticed by php without a reboot.
This may be a separate issue, but I will mention it in case it is pertinent. I notice that the time will slowly go out of sync, about 1 minute per day. I did setup ntp as the per instructions here. I can verify that the service is installed correctly and is running, but it does not seem to help to correctly sync the time. I do not want to focus too much on the time sync issue unless it is thought to be part of the main problem of the timezone being reset.
One more thing to mention which I believe may be a common side effect of running a virtual copy of linux is that I am unable to update the hardware clock using the following command:
The response I get back from this command is:
"Cannot access the Hardware Clock via any known method. Use the --debug option to see the details of our search for an access method."
Also, /etc/sysconfig/clock always has UTC=true set. This doesn't seem to be affected by the timezone reset that happens.
Although I am able to "fix" this issue by replacing the /etc/localtime file, I need to find a solution that does not require me to reboot my server. I am curious, but I do not necessarily need to find out exactly why my timezone is being reset, as long as I can find a solution that works for me. I spent too much time and energy on this problem already and I just want it fixed, even if it is some kind of hack.
I have a few ideas that I need help with, and I am hoping that those with more knowledge about these things can help me choose the best answer to this issue.
- Since I can verify that the timezone value in whm is what the timezone is being changed to, I am wondering what commands whm uses to set the timezone. How can I find out what directory whm is installed to on my server? Maybe it is not recommended but is it possible for me to view and even edit the source files for whm? What I would like to do is find the source for the whm timezone routine. Depending on how it works maybe I can just run the proper command(s) with the UTC timezone and maybe even edit the code to add UTC into the dropdown list. This way, even if the timezone is still being reset, it will just reset back to UTC and it will not affect me.
- Since I need to replace the /etc/localtime file to fix this issue every time, it seems feasible that somehow this file is being replaced automatically without my input. A quick and dirty solution might be to chmod the /etc/localtime file somehow so that whatever script is trying to replace this file will be denied? I haven't tried this yet, but I would like to know thoughts on this. This doesn't explain how the time/timezone is properly reflected in php without a reboot (unless a reboot IS actually happening at this same time and I am not privy to it? - Where can I check logs to figure this out?)
- This may be going out of the scope of this site, but the last thing I can think of is to somehow set php and mysql time/date/timezone to something else other than the local computer time. I experimented with this a bit earlier but somehow I still wasn't getting the right time that I wanted even though UTC was selected.
Thanks to all who take the time to read and respond to this massive question!