Question

I'm trying to write a simple online music player to improve my programming.

I have a server running CentOS 6.5, with an external hard disk containing all my files. I mounted my storage partition to /mnt/storage and my music is in /mnt/storage/cascornelissen/Muziek, which has the following permissions:

drwxrwxr-x 19 cascornelissen ftpusers       4096 Nov  4 14:43 Muziek

Then I have a simple httpd webserver, hosting the project in /var/www/html/melodi, which constains a softlink to the Muziek directory mentioned earlier:

lrwxrwxrwx 1 root           ftpusers   34 Jan 26 22:31 music -> /mnt/storage/cascornelissen/Muziek

I want to use PHP's glob to list all the files but that returned an empty array. So I tried scandir("music") but it returns the following error:

Warning: scandir(music): failed to open dir: Permission denied in /var/www/html/melodi/index.php on line 42

Any ideas on how to fix this permissions issue?

Was it helpful?

Solution

Try this:

chmod ugo+x /mnt /mnt/storage /mnt/storage/cascornelissen

Probably some part of your path will not allow entry for your Apache user. Allowing entry to a directory means adding x or execute permissions to the directory.

Explanation

# create path a/b
mkdir -p a/b
ls a/b          # this works

# now remove all permissions for a
chmod 000 a
ls a/b          # ls: cannot access a/b: Permission denied
                # but why, we should still have permission for b??
                # Now, lets add x permission for a:
chmod ugo+x a
ls a/b          # works again
ls a            # ls: cannot open directory a: Permission denied
                # So, we cannot list contents of a, but we can
                # access a/b *through* a

So, execute permission or x for a directory means we can access the path below it, even if we cannot read the contents of the directory itself. In your case, Apache needs permission to "walk through" /mnt/storage/cascornelissen even though it will not read any files until it reaches Muziek.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top