Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a txt-file one of my user's homedir which is regularly updated there by a script. I now want to be able to access (read) this file from the web.


So what I tried now is to log in as root, go into my webservers httpdocs folder


and there I tried to create a symbolic link with

ln -s /home/user/foler/file.txt /var/www/path/to/domain/httpdocs/file.txt

But this didn't work... I already tried changing the chmod of the symlink (which changes the ones from the original file of course) and also a chown to the user from webserver, but no matter what I tried I cannot open the file from the web or from a php-script (which is what I want to do)

Can anybody help me and tell me what I need to do? What rights do I need to give? Or is there another way of achieving this?

share|improve this question
can you try chmod o+r /home/user/folder/file.txt – jet Feb 18 '11 at 23:40
up vote 2 down vote accepted

The symbolic link will always have these permissions: lrwxrwxrwx. The "l" indicates that it is a link. Therefor, all users can follow the link because the effective permissions are those of the file to which the link points. It is never useful to try changing the permissions of a symbolic link.

The whole path from the root to the file in question must be readable by the Apache user. So... take a look the permissions of the home folder:

ls -la /

The home directory should be owned by root, group owned by root, with 0755 permission mask by default: drwxr-xr-x. If not, change it:

sudo chown root:root /home; sudo chmod 0755 /home

Now take a look at your user's directory:

ls -la /home

If the username in question is sambo, the user's home directory should be owned by sambo, group owned by sambo, with 0755 permission mask by default: drwxr-xr-x. If not, change it:

sudo chown sambo:sambo /home/sambo; sudo chmod 0755 /home/sambo

Repeat this as many times as needed, for however many directories exist until you reach the directory that contains the file. Then, don't forget about the file itself.

sudo chown sambo:sambo /home/sambo/path/to/file/file.txt; sudo chmod 0644 /home/sambo/path/to/file/file.txt

Then use PHP to open it:

    $file = '/home/sambo/path/to/file/file.txt';
    $fp = fopen($file, 'r');

You could use the symbolic link at this point, too.

share|improve this answer
Well I've tried that... I set the whole path from home to the directory of the file to chmod 0755 and the file itself too. But still the script cannot read the file nor can I directly open it yet... – evident Feb 19 '11 at 11:36
Are you running PHP in safe_mode? (You would have to to chown your file to www-data. 'chown www-data file.txt'). Any errors in Apache log file? – user8290 Feb 19 '11 at 14:59
I went the other way now which worked for me... I had teh script write it directly into the /var/www/... path, but I needed your chmod changes here to have it writable there... thank you! – evident Feb 19 '11 at 16:37

as I remember I was able to access files from my system with mediatomb Install mediatomb as it has a web UI. I would recommend enabling password protection at least.

Another alternative is opera unite web server.

Hope this helps.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.