Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

/home/user/folder/file.txt

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

/var/www/path/to/domain/httpdocs

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
    

2 Answers 2

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:

<?php
    $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 http://mediatomb.cc/pages/documentation 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

 
discard

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.