Question:
Linux accessing textfile through website when file is in root folder?
Deception
2012-04-21 04:43:34 UTC
I have program running on my linux server. It updates a textfile in the root folder with various infomation. How can I access this from my website. The website is running on the same server. Is there a way to create a textfile in the website folder and clone it with the one in my root folder? I have tried creating a symlink (ls -s) but when I try accessing it via the website. It gives me permission denied error. I have changed all the relvent file permisions to 777. Still doesn't work.

Any Ideas would be great
Five answers:
samantha
2012-04-21 04:46:13 UTC
permission 777 is ridiculously insane... you would allow an executable file in the root folder to be edited via a website?



that is simply begging for trouble



i think it is monumentally foolish to have web content from /root at all - and a "textfile" certainly doesn't require execute permissions... you could simply run a cron job to sync the files once a minute (or whatever interval is appropriate) using something like rsync which compares the two folders and updates the contents when a newer version is seen.
Whatevers
2012-04-21 11:48:55 UTC
Yeah, do not try to put the file in your root directory. That's not going to work, since your web server software is probably set to only access files in a limited area. That's why your symlink isn't working either. What program are you using to set that various information up? What webserver? Have you tried putting the contents of that file into a location your web server is set to access? Even a separate script would work.
ratter_of_the_shire
2012-04-21 13:50:58 UTC
Better to have a cron script periodical copy the file into the web root directory. Apache purposely avoids letting a site script access anything outside the web root directory. (And it's a good idea to keep it that way)
?
2012-04-23 15:22:53 UTC
You NEVER want to give web access to the root of your file system.



I would suggest if you need to read the file from a browser that you modify the script that writes it, and output the file to a web directory instead.



my take is this



if your script writes a file instead of doing "command > logfile "



do



"command > /var/www/html/logifle"



or as ratter mention do a scheduled task that will periodically copy or move the file from / to your $webroot
James Bond
2012-04-21 12:31:03 UTC
may be check .htaccess file setting


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...