0

I'm trying to set up an Apache 2 server on my Arch Linux machine. Everything works great so far, including https and php, but now I want to change the DocumentRoot from the default /srv/http to /var/www/foo. I changed DocumentRoot /srv/http and <Directory "/srv/http"> to DocumentRoot /var/www/foo and <Directory "/var/www/foo"> respectively and reloaded the configuration using systemctl restart httpd. Now I'm getting 403 errors when trying to access https://localhost or anything within.

Further investigation turns out that changing the <Directory ...> declaration has an effect, but changing the DocumentRoot doesn't. When I set Require all granted in <Directory /> to eliminate these 403 errors, it turns out Apache is still trying to serve documents from /srv/http. For instance, I put a test.php file containing <?php echo exec('pwd'); ?> into both /srv/http/ and /var/www/foo/ and accessing https://localhost/test.php outputs /srv/http to my browser. Trying to access documents located in /var/www/foo but not in /srv/http will result in 404 errors.

Why is Apache still using /srv/http? I changed absolutely every occurence of /srv/http to /var/www/foo in /etc/httpd/conf/httpd.conf and restarted Apache several times, but my document root just won't change. According to the Apache Arch Wiki article, I've done everything that's necessairy.

I could of course just symlink /srv/http to the desired location, but that doesn't seem like the proper way to go.

Here are the parts of my httpd.config that I think might be relevant:

<Directory />
    AllowOverride none
    Require all granted     # Will of course change to denied again once everything works
</Directory>

DocumentRoot "/var/www/foo"

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

Of course, /var/www/foo itself and all parent directories have at least 755 permissions.

1 Answer 1

1

Do you have any VirtualHost sections in httpd.conf? If you have a VirtualHost section with /srv/http set as its DocumentRoot, it is possible Apache is using that directory from the VirtualHost section, even though you have changed the DocumentRoot value outside of the VirtualHost section.

4
  • No, I don't have any virtual host set up. Besides, that wouldn't make a difference because I used vim's search feature to make sure there is no occurence of /srv/http left.
    – Raptilicus
    Apr 7, 2017 at 19:39
  • 1
    Though the problem you encountered may be unrelated to a VirtualHost setting, Apache can also load virtual hosts from an external file, e.g. Include conf/extra/httpd-vhosts.conf - see How To Set Up Apache Virtual Hosts on Arch Linux - so you could check to see whether that line exists and is or is not commented out in httpd.conf. If it isn't commented out, you could put a # at the beginning of the line to make it a comment and restart Apache to see whether that makes a difference.
    – moonpoint
    Apr 7, 2017 at 19:47
  • @Raptilicus, you could also check the main error log to see if there is anything unusual there that might offer a clue to the problem. The location for that file is shown if you run apachectl -S. That also shows the default value for DocumentRoot, but the value you see for DocumentRoot there is not necessarily the one used for localhost if a VirtualHost section is in effect either within httpd.conf or from an external httpd-vhosts.conf file.
    – moonpoint
    Apr 7, 2017 at 20:05
  • The vhosts.conf was not included. But investigating further in that direction, I found out that httpd-ssl.conf contained such a virtual host setup explicitly using /srv/http. I changed that to /var/www/foo, too, and now everything works! Thanks!
    – Raptilicus
    Apr 7, 2017 at 20:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .