1

i have been struggling for a couple of days about this problem. I am trying to change the default www directory for Apache/2.4.6 (Ubuntu) web-server under LinuxMint16 and making it point to a NTFS hard disk that i share with another Windows installation. This hard disk is mounted under /media/crash/Yari and no matter what i try, nothing works..while if i change the default www directory to something else in the same hard disk where linux is installed, everything works as expected.

Following are all the changes i have made in order to try to get things working:

The folder where i want my new www is /media/crash/Yari/www I have thus edited the /etc/apache2/apache2.conf file:

DocumentRoot /media/crash/Yari/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /media/crash/Yari/www>
    #Options FollowSymLinks
    Options Indexes FollowSymLinks Includes ExecCGI MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

Afterwards, as i have seen from this post https://askubuntu.com/questions/11840/how-to-chmod-on-an-ntfs-or-fat32-partition/91054#91054 i have determined my hard disk UUID by typing

sudo blkid

and edited the file /etc/fstab adding this line UUID=#my-hd-uuid# /media/crash/Yari ntfs-3g auto,users,permissions 0 0

To be sure that the apache user (in my case: www-data) had the permissions to access the files inside the new www directory i have changed the group and the owner of all the files inside the hard disk with

sudo chgrp -R www-data /media/crash/Yari
sudo chown -R www-data /media/crash/Yari
sudo chmod -R 775 /media/crash/Yari

I have checked the permissions of the new www directory and the files contained in it by doing

sudo ls -l /media/crash/Yari

and all the files and dir appear as drwxrwxr-x 1 www-data www-data so the previous permissions modifications where done correctly.

Unfortunately i am surely missing something as all the above have been useless! Hope someone can help, thank you very much for any assistance.

2
  • 1
    What are the permissions of /media and /media/crash?
    – Jenny D
    Jan 9, 2014 at 11:29
  • The permissions of /media/crash are drwxrwxr-x 1 www-data www-data instead the one of /media are drwxr-x---+ 3 root root. Do you think i should change the permissions of /media?
    – Yari
    Jan 9, 2014 at 14:13

2 Answers 2

2

In order for apache to access a directory, it must have access rights not only to that directory but to all directories above it. So you need to allow www-data read access to /media and /media/crash as well as /media/crash/Yari.

In general, I would recommend that the apache user not have write access to the directory where the web pages live. It should be enough to allow writing to the directories used for logs, run/pid files and any cache files. Of course if you have e.g. a cgi application that writes to disk, you must allow it to do so, but it would be more secure to keep any such files in a separate directory.

In any case, to solve the immediate problem, either change group ownership of /media and /media/crash to www-data, or change their permissions to 755.

2
  • Thanks Jenny for you quick and detailed answer. Inspired by you i have used another method that has apparently solved the problem, i will post it here in some hours because right now my account has some limitations.
    – Yari
    Jan 9, 2014 at 14:49
  • thank you. I am going to implement this for now but I am still looking for a better answer :) Mar 16, 2019 at 19:08
1

I was a bit afraid to change the permissions of /media because i have 2 other hard disks under that directory that i have to use under windows and the last permission change on /media/crash/Yari made that hard disk unwritable under windows.

So what i did was to edit the file /etc/fstab by changing the line

UUID=#my-hd-uuid# /media/crash/Yari ntfs-3g auto,users,permissions 0 0

into

UUID=#my-hd-uuid# /sharedhd ntfs-3g auto,users,permissions 0 0

the new default-www would then have been /sharedhd/www and i had not to change the permissions of /media and /media/crash.

Finally i want to point out that changing the ownership of some folders using

sudo chgrp -R www-data /media/crash/Yari
sudo chown -R www-data /media/crash/Yari

was, in my case, a mistake because it corrupted the ownerships in windows too making all the files and folders inaccessible. The only thing that i had to do was to change the /etc/fstab file and to change the permissions with

sudo chmod -R 777 /sharedhd

Unfortunately by giving 775 permissions i was unable to edit those same files and dirs under windows so i was forced to use 777...If this method has some drawbacks i should be aware of, or if there is some better way of doing it without giving root access to all files please let me know!

1
  • About permissions: The danger is that if your webserver is compromised, e.g. by an attacker abusing a cgi script that you run there or some other security issue, they can overwrite all the files that are writable by the webserver. How dangerous this may be will depend on your environment. The standard advice is to restrict write access to only those few directories necessary for the server to function.
    – Jenny D
    Jan 10, 2014 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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