It's been two days now without a solution, so I'm asking for help. I've searched and tried, I solved a few problems already but there is one last thing.

This is what I'm trying to do: change the default directory of apache2 from /var/www/html to /media/pi/storage/root_folder/

I have followed this tutorial > https://help.ubuntu.com/community/ApacheMySQLPHP#Virtual_Hosts

under section virtual hosts, I created a test html at /home/pi/Desktop/ and it works because of (I assume) correct permissions.

Now when I do the exact same thing at /media/pi/storage/root_folder/ and reload the webpage, I get forbidden error message, suggesting that I have permission (again, I assume this is right) issues on my hard drive (which is formatted with ext4)

Will something like this work? sudo chown -R USER:USER /media/pi/storage/root_folder/ OR chgrp -R www-data /username/ chmod -R 2750 /username/ OR it's something else?

I don't know what command is needed, a step-by-step would be greatly appreciated

And finally, how do I get these permissions to be applied for any new subdirectories and files in the future so that I don't run into the same forbidden error ever again?

I appreciate any help, thanks guys..

The virtual host configuration file:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /media/pi/storage/root_folder/

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Apache error log snippet:

[Sun Dec 17 05:29:33.304748 2017] [core:error] [pid 951:tid 1836053552] (13)Permission denied: [client] AH00035: access to / denied (filesystem path '/media/pi/storage') because search permissions are missing on a component of the path

Output of ls -ld /media /media/pi /media/pi/storage:

drwxr-xr-x  3 root root 4096 Nov 29 02:57 /media
drwxr-x---+ 3 root root 4096 Dec 17 05:28 /media/pi
drwxr-xr-x  4 pi   pi   4096 Dec 16 20:31 /media/pi/storage
  • 1
    @J.Starnes The text in the images is not relevant anyway, I'll just remove them. – fkraiem Dec 17 '17 at 6:05
  • @fkraiem Very well, the comment was meant to encourage the op to understand the encouraged practices. – J. Starnes Dec 17 '17 at 6:10
  • ok, won't do it again in the future – johndoe666 Dec 17 '17 at 6:24

You must also allow Apache to access that directory. By default, Apache is only allowed to access /var/www and /usr/share; this access is granted by blocks like this in /etc/apache2/apache2.conf:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted

Thus you must add a similar block somewhere in your Apache configuration, to grant access to /media/pi/storage/root_folder/:

<Directory /media/pi/storage/root_folder/>
        Require all granted

If you already have a <Directory /media/pi/storage/root_folder/> block, for example in your virtual host config file, just adding the Require all granted directive to it will be sufficient.

In addition, the error log shows that Apache (i.e., the www-data user) does not have read or search permissions to a component of /media/pi/storage. The output of ls -ld /media /media/pi /media/pi/storage shows that /media and /media/pi/storage both have 755 permissions, so the culprit must be /media/pi. Since /media/pi is using Access Control Lists (as denoted by the + sign in the output of ls -ld), we give www-data read and search permissions with

sudo setfacl -m u:www-data:rx /media/pi
  • I need to first install acl.. EDIT: That worked ! Ok, now to reboot and see if it persists – johndoe666 Dec 17 '17 at 6:04
  • ok, works after a reboot, the index.html is served but when I click on a link, it says file not found, i've double checked the file path and it is correct. It says > /virtual tours/2nd place/2nd.html was not found on this server. the virtual tours does not have a space on my drive, it is virtual_tours with an underscore. Why is apache not getting that? EDIT: My full path is > /media/pi/storage/root_folder/virtual_tours/2nd place/2nd.html but it seems that when I click on the link, apache is getting virtual tours (without the underscore) – johndoe666 Dec 17 '17 at 6:15
  • @johndoe666 That probably should be a different question. If the permission issue is solved, please accept the answer, and then post a new question about the link issue. – fkraiem Dec 17 '17 at 6:21
  • Okay, nevermind, my html code was wrong. I can solve that myself. Thank you very very much sir ! Many many many thanks to you, this has been bothering me for the past two days. haha, now it's solved ! – johndoe666 Dec 17 '17 at 6:22
  • Final note, this solution could help quite a few people out there who are facing a similar issue, after all, this is a commonly asked question, is there a way to share this solution to others in the future? – johndoe666 Dec 17 '17 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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