0

I have static resources (mp3s and images) that I want to use in a website hosted on Apache virtual host with the following configurations:

<VirtualHost *:80>
ServerName example.com
    serverAlias myexample.loc   
    DocumentRoot /home/USER/www/yii2/web
    <Directory "/home/USER/www/yii2/web">
        AllowOverride All
        Options Indexes FollowSymLinks MultiViews
        Require all granted
    </Directory>
</VirtualHost>

The resources are found on flash memory on a path like the following:

/media/USER/KINGSTON/audio

I have created a symbolic link for the above directory in the site's document root using ls -s like the following:

sudo ln -s /media/USER/KINGSTON/audio /home/USER/www/yii2/web 

However, trying to access any resource leads to 403 Forbidden error. How could I give secure permissions that allows the www-data user to access it?

SaidbakR
  • 769

1 Answers1

0

What is the permissions of the /media/USER/KINGSTON/audio directory? Remember that Apache needs +x on directories it traverses.

Thus /media/, /media/USER, /media/USER/KINGSTON/ and /media/USER/KINGSTON/audio needs to have +x for world for www-data to be able to access it. This can be done with sudo chmod +x /path, for each of the directories above. If the KINGSTON device is not a unix filesystem, you may get into challenges there, as it does not have the traditional Unix ACLs.

Furthermore, I would probably add it as a normal mount point if it's a permanent solution. For how to do that, have a look at this Q&A

As a short example - note that # as prompt denotes commands run as root, $ denotes normal user.

/tmp # mkdir foo
/tmp # chmod 754 foo
/tmp # cd foo
/tmp/foo # mkdir bar
/tmp/foo # chmod 755 bar
/tmp/foo # ls -la
total 20
drwxr-xr--  3 root root  4096 Dec 24 14:24 .
drwxrwxrwt 57 root root 12288 Dec 24 14:23 ..
drwxr-xr-x  2 root root  4096 Dec 24 14:24 bar
# Note that the directory bar has read and execute permissions for everyone, but /tmp/foo has only read for others than group and user.
/tmp/foo # echo "foo" > bar/foo 
$ cd /tmp/foo/bar
bash: cd: /tmp/foo/bar: Permission denied
$ cat /tmp/foo/bar/foo
cat: /tmp/foo/bar/foo: Permission denied
/tmp/foo # chmod +x . #Add execute permission for world to /tmp/foo
$ cat /tmp/foo/bar/foo
foo
vidarlo
  • 22,691