403 Error after adding a new website directory

On an ubuntu server it is common to host site files in a directory with a structure like ‘/var/www/example.com’.

One might wish to separating a subdomain out from site files in another directory. Something like ‘/var/dev/example.com’.

How to fix or prevent a 403 error after adding a new site directory

To prevent a 403 error, remember to edit the /etc/apache2/apache2.conf file to allow this directory to be accessed from the outside world.

The /etc/apache2/apache2.conf file has a ‘Require all granted’ directive for the normal /var/www directory that looks like this:

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

Make a copy of this directory for the new directory that are creating and add it to the /etc/apache2/apache2.conf file.

<Directory "your directory here">
   Order allow,deny
   Allow from all
   # New directive needed in Apache 2.4.3: 
   Require all granted
<Directory>

Once you have updated this file, remember to restart apache.

sudo service apache2 restart

Leave a Reply

Your email address will not be published.