Possibly small problem in a server: why some dates are not in my timezone?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Possibly small problem in a server: why some dates are not in my timezone?
I have an account in a Debian GNU/Linux 9.4. I have no root access there.
In my server uses I have:
- date and time are correctly shown in SSH access
- ~/public_html/php.ini exists and contain a line to set my timezone ( the line is like date.timezone="Inside/Somewhere" )
I created a folder inside ~/public_html and put a few files there. Now I want to show these files and their dates to people. When I list that folder in SSH, the dates are correct. But when I open that folder in my browser (accessing the folder like anyone in the world can do), the time is in a different timezone.
Searching for the keypoint of my problem, I found nothing as clear as I need.
But this info may be useful for you:
Code:
$ ssh me@server
$ cat ~/public_html/folder/t.php
<?php
phpinfo();
?>
$ # visiting that t.php file in the browser shows also this line:
$ # "Loaded Configuration File" -> /etc/php/7.0/apache2/php.ini
$ # Copying public_html/php.ini to p_html/folder does not change anything
$
What should I do to have the correct (or as I want) files' folders times?
I wrote there the usual timezone name I know (it uses the wrong city as reference for the timezone, but this problem is scattered almost anywhere). Reloaded the t.php from the browser, no change.
Second, I changed the timezone name to something I saw in the web, which had the correct city. "Great, this should be the problem!" - I thought. Reloaded the t.php tab, but also no change.
Then I tried to find a page listing the timezone names I could choose from. Could not. Can you point it to me?
The .htaccess file (also) should work! My web root folder has one, with a directive that surely work correctly. It changes the 404 errors everywhere to something I chose. I also tried the two timezone I tried before in the root .htaccess, no success.
If I am in the situation that needs root to do something, I would like to confirm the situation. I have no clue of what else to do. With that, I can contact the server admin and (possibly) ask for changes.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Rep:
The timezone is set by the client. It shows differently with ssh because you're logged into the server, so you see its time, not the client's time. But with browsers it shows the clients time zone.
Last edited by AwesomeMachine; 05-12-2018 at 07:52 PM.
The timezone is set by the client. It shows differently with ssh because you're logged into the server, so you see its time, not the client's time. But with browsers it shows the clients time zone.
I am confused with that. The server time is *not* in my timezone. Although the times I see for my files there are shown in my timezone. This is consequence of my user environment, I think:
Code:
$ ssh me@server
$ # my shell is Bash
$ set | grep TZ
TZ=America/Sao_Paulo
My timezone is that one, America/Brasilia (which is the correct name for the common America/Sao_Paulo). I have tried both values in the steps I described in the first message.
If the files seen through the web server (for example: http://me.server.net/folder/ ) were shown in my timezone, that would be exactly what I want - but
this does not happen.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Rep:
OK, I understand. If you're just looking at a file path in a browser--nothing in html--it will probably not adjust the file metadata according to the client's TZ. That would be chaos. I'm not sure if I'm understanding this correctly.
When you ssh into the server the file metadata is different than if you point a browser to the same files?
OK, I understand. If you're just looking at a file path in a browser--nothing in html--it will probably not adjust the file metadata according to the client's TZ. That would be chaos. I'm not sure if I'm understanding this correctly.
Yes, it would be chaos, of course. Browsers would need to know which timezone each remote page is, which is a very strange idea. So they do not change anything the remote server sends (through sites).
Quote:
Originally Posted by AwesomeMachine
When you ssh into the server the file metadata is different than if you point a browser to the same files?
The answer is close to "yes and no". The metadata of the files are just one, the server's filesystem date for the files I uploaded. But they are shown with different values depending on how I list them.
I may I want to set my site's (of my account in that server) timezone to a specific value, to coincide with my timezone. My bash environment has it set, as I discovered.
Now, my steps can be summarized in:
1. I created a few local files (where they have time creation metadata, which does not matter)
2. I uploaded those files to server using scp (where they got similar metadata, with just a few minutes difference)
3. I created a new folder in my server. This folder path *there* is ~/public_html/nf/ (nf = short for "new folder")
4. I moved the uploaded files to that folder
5. I listed (from there) the folder contents, using my common 'ssh me@server' access. Their times are shown in my timezone (their creation date is the time I uploaded them, which is correct). I see the right time here as consequence of my TZ var in environment there (I imagine).
6. In my local browser (here), I open the page http://me.server.fi/nf/, which present me with a list of the files I moved in step 4. But their metadata time is not correctly shown! They are different. They are in a different timezone (my statement!), comparing with the times seen with 'ls -l' I did through ssh.
Do not forget the ways I tried to fix the shown time:
- add a new "~/public_html/php.ini" directive
- a new "php.ini" file put in nf remote folder, with the same directive
- checked which config PHP use, with "phpinfo()" function, but I am far from sure that I interpreted it right (it did not say to read my .ini file, which I am pretty sure it does)
- remotely listing my files with ssh needed no change, as said
- added a new ~/public_html/.htaccess (remote file) directive, but it did not work. The .htaccess existed, and has directives that clearly work
- created a new remote file ~/public_html/nt/.htaccess with the timezone directive, but it also did not work
I am not sure to understand how files dates (last modified dates?) relate to timezone...
I mean I don't get why file dates are different in ssh session and in apache directory listing
I am not sure to understand how files dates (last modified dates?) relate to timezone...
I mean I don't get why file dates are different in ssh session and in apache directory listing
My guess of my shell environment adjusting them in ssh session is not true?
Thank you for that pointer! I could not find it. Unusual reading for me.
Quote:
Originally Posted by keefaz
Could you show some example of different file dates you see (from ssh and from http)?
Yes, sure I can!
ssh session below. Note that my PS1 has two lines! It shows time, "user@server", folder and the common "$" in the second line.
Code:
$ ssh me@server
...
# login lines, which do not matter here, removed
...
17:36:35 me@server:~
$ 'ls' -l public_html/nf/
total 608
-rw-r--r-- 1 me me 127311 May 12 13:43 289.jpg
-rw-r--r-- 1 me me 151157 May 12 13:43 295.jpg
-rw-r--r-- 1 me me 152416 May 12 13:43 297.jpg
-rw-r--r-- 1 me me 175432 May 12 13:43 298.jpg
-rw-rw---- 1 me me 646 May 12 14:20 php.ini
-rw-rw---- 1 me me 23 May 12 14:18 t.php
17:36:55 me@server:~
$ # ls between single quotes is to avoid my
# alias: ls='ls -sh --color=auto'
17:39:47 me@server:~
$ # Right now my local time is ~17:40,
# as I write this post
Note that 13:43 is the correct localtime (for me) when I created and uploaded those files.
Now a screenshot of that I see in the browser, which (should not matter) is Firefox 52 ESR. The times shown here are exactly 5 hours different, which seems correct for my timezone difference idea.
I do not show a browser window because I can take screenshots of all pages parts, even unshown ones, with the "Abduction!" Firefox extension. The address of that shot was said before: http://me.server.fi/nf/ (actually, the real server is .nl, if you wonder).
Maybe try to edit your .haccess file and add timezone environment with this line
Code:
SetEnv TZ Europe/Amsterdam
Not sure it will work, it needs mod_env apache module loaded
That kind of line is exactly what I have tried before, with .htaccess (both in my HTML root and in nf folder).
Trying to find if the module is loaded, I found an SO thread that points to the apachectl command. But that command does not exist on my server:
Code:
# in SSH session:
20:27:23 me@server:~/public_html/nf
$ vim .htaccess
20:53:12 me@server:~/public_html/nf
$ set|grep TZ
TZ=America/Sao_Paulo
20:53:16 me@server:~/public_html/nf
$ apachectl -M
-bash: apachectl: command not found
20:55:53 me@server:~/public_html/nf
$
There seems to be a better SO thread for debianish distros. Indeed, the second paragraph in the first answer has this:
Quote:
Debian/Ubuntu butcher the apache configuration into a large number of files, where directories of mods and sites enabled are symlinked to other snippets of configuration files. The a2enmod/a2ensite scripts just manipulate these symlinks.
That "env.load" is the env module I am trying to use? It points to "../mods-available/env.load"
Now I am trying to find if I can enable the env module for my user. If I cannot, I will ask that for the server admin. Any ideas that can be added to that message? Comments are welcome!
Maybe try to edit your .haccess file and add timezone environment with this line
Code:
SetEnv TZ Europe/Amsterdam
Not sure it will work, it needs mod_env apache module loaded
Forgot to say in #9: in my server, the only command started with a2 is a2ping. There are no a2enmod and a2ensite, as the paragraph I quoted points. Should I ask for those commands for normal users, like me? Or everything done with these commands must be done by root?
Thank you for these detailed instructions. Sometimes there are important details we may be missing.
Before, I did use SetEnv in .htaccess changes. Now I will edit one of my previous posts with that detail. I thought it was not important to say that, so I kept for me, assuming it would be the only way to use .htaccess for what I wanted.
I just did those steps, and now I have the following situations in 3 windows:
- window 1: an open browser tab, with my infos.php loaded
- window 2: another open browser tab, showing my remote nf folder loaded
- window 3: an ssh me@server session open in a terminal, where I just did the command 'ls -l public_html/nf'
These windows have: the shown enviromanet variables are shown with the variables we set in .htaccess; the "Last modified" dates are correct, but times are incremented 5 hours; the dates and times shown in terminal are correct - which is different from what is shown in the browser. I made sure to reload the browser windows, in a way to avoid using any local cache of previous situations.
Yes, no matter how you change the timezone variable environment, apache seems to stick with the system timezone...
Maybe a workaround would be to "fake" the apache directory listing page for your images using php and mimic the default page visual...
Then you could set any timezone value you want to display the last modification dates
Yes, no matter how you change the timezone variable environment, apache seems to stick with the system timezone...
Yes. Pretty much that. Do you (and others reading this thread) think that all of the facts, in the context we worked and tested, are reasons to submit a bug in Apache? I even wonder why that did not already happened.
Quote:
Originally Posted by keefaz
Maybe a workaround would be to "fake" the apache directory listing page for your images using php and mimic the default page visual...
Then you could set any timezone value you want to display the last modification dates
Yes. That is easy. I would simply save the rendered page, edit and upload it as index.html, so it is not necessarily visible for who opens that folder's page.
For the same idea, if someone knows a simple and easy to use (enough to what I want!) PHP script for listing files, please point. I imagine there should be a lot of those. But searching, examining and chosing, may take more time than making a (possibly) "fake solution", like we said.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.