2

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?

2 Answers2

2

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.

0

I was able to access files from my system with mediatomb (see the documentation) as it has a web UI. I would recommend enabling password protection at least.

Another alternative is opera unite web server.

Zanna
  • 72,312
Allan
  • 11,672