I'm using Apache 2.4.41 on Ubuntu 20.04.

With the following configuration, I can successfully view the default Ubuntu Apache page at /var/www/html/index.html:

<VirtualHost *:80>
        # Server Name
        ServerName example1.org
        ServerAlias dev.example2.org

        DocumentRoot "/var/www/html"


If I try to change the DocumentRoot directive, however,

<VirtualHost *:80>
        # Server Name
        ServerName example1.org
        ServerAlias dev.example2.org

        DocumentRoot "/home/rufus/www/html"


then any attempt to view the file /home/rufus/www/html/index.html returns a 403 Forbidden error.

Both target directories have the same ownership and permissions all the way to the root directory. From ls -lh:

drwxr-xr-x 14   root root  /var/
drwxr-xr-x 3    root root  /var/www/
drwxr-xr-x 2    root root  /var/www/html/
-rw-r--r-- 1    root root  /var/www/html/index.html


drwxr-xr-x 10 root root  /home/
drwxr-xr-x 11 root root  /home/rufus/
drwxr-xr-x 13 root root  /home/rufus/www/
drwxr-xr-x 10 root root  /home/rufus/www/html/
-rw-rw-r-- 1  root root  /home/rufus/www/html/index.html

I try the same URLs in both cases, http://dev.example2.org and http://dev.example2.org/index.html. I'm also certain to reload Apache after every config change.

This question is pretty much identical to mine. The only answer suggests adding a block like

<VirtualHost *:80>
        # Server Name
        ServerName example1.org
        ServerAlias dev.example2.org

        DocumentRoot "/home/rufus/www/html"

        <Directory /home/rufus/www/html>
            Options FollowSymLinks 
            AllowOverride All
            Order deny,allow
            Allow from all


I tried this with both Allow from all and Require all granted (as noted in a comment there), reloading Apache after each change. The second configuration continues to give me a 403 error.

Why does the 2nd one give a 403 Forbidden error, and how do I change my DocumentRoot?

  • If you're really hitting dev.example2.com, the virtual host you showed isn't answering that, because it's for dev.example2.org. – Andrew Schulman May 6 at 23:48
  • @AndrewSchulman Whoops, no, that was a typo when writing the question. Good catch. Edited. I'm attempting to access the correct URL. – Borea Deitz May 6 at 23:57
  • 1
    It's best not to set the document root to anywhere in /home because the user directories have 700 permissions which is why you are getting the Forbidden error. – Nasir Riley May 7 at 2:37

Did you set the new directory in the default document root? Should be about line 292.

288 # DocumentRoot: The directory out of which you will serve your
 289 # documents. By default, all requests are taken from this directory, but
 290 # symbolic links and aliases may be used to point to other locations.
 291 #
 292 DocumentRoot "/var/www/html"
 294 #
 295 # Each directory to which Apache has access can be configured with respect
 296 # to which services and features are allowed and/or disabled in that
 297 # directory (and its subdirectories).
 298 #
 299 # First, we configure the "default" to be a very restrictive set of
 300 # features.
 301 #
 302 <Directory />
 303     Options FollowSymLinks
 304     AllowOverride None
 305 </Directory>
 307 #
 308 # Note that from this point forward you must specifically allow
 309 # particular features to be enabled - so if something's not working as
 310 # you might expect, make sure that you have specifically enabled it
 311 # below.
 312 #
 314 #
 315 # This should be changed to whatever you set DocumentRoot to.
 316 #
 317 <Directory "/var/www/html">
  • This appears to be a very specific config file. In Ubuntu, the relevant Apache config files are /etc/apache2/apache2.conf and whatever's in /etc/apache2/sites-enabled/. Neither of those files on my system look like what you've posted. The sample config I gave in the question is in the latter category, and I'm sure that's the appropriate place to set the DocumentRoot. – Borea Deitz May 7 at 0:00
  • What I posted was default Apache config from a CentOS install. Run grep -i documentroot /etc/apache2/apache2.conf – PMTucker May 7 at 13:27

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.