Moving your default DocRoot

If you want to change your default DocumentRoot path, there are at least two things you need to update.

  1. The DocumentRoot directive
  2. The <Directory> block associated with the DocRoot.

As each DocumentRoot needs a matching <Directory> block, be sure to update both to reflect the new location. If you only change the DocumentRoot path, you will get a 403 Forbidden error in your browser.

Example Old Configuration

For example, your old config may have looked something like this:

...

DocumentRoot /usr/local/apache2/htdocs

<Directory /usr/local/apache2/htdocs>
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
...

Example New Configuration

Now let's say you want to move the DocRoot to /var/www; you will need to update both of them.

...

DocumentRoot /var/www

<Directory /var/www>
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
...

These steps not only apply to the main server config, but also any VirtualHosts you want to change.

  • No labels