Search code examples
htmlapachevhosts

Apache giving 403 forbidden errors


Ok, so i've previously set up two virtual hosts and they are working cool. they both house simple web projects and work fine with http://project1 and http://project2 in the browser.

Anyway, I've come to add another vhost. I edited the /etc/hosts file with 127.0.0.1 project3 and also updated the httpd-vhosts.conf file by copy and pasting the previous entries for project2 and editing the file path.

I've checked all the file and folder permissions (in fact I copied and pasted from project2) and simply put a "hello world" message in the index.php file.

I get a 403 forbidden permission denied message when accessing http://project3

Why is this, I just can figure out what step I've missed as everything seems to be set up correct.


Solution

  • Check that :

    • Apache can physically access the file (the user that run apache, probably www-data or apache, can access the file in the filesystem). For instance, you can use sudo su www-data to start a shell session as www-data.
    • Apache can list the content of the folder (read permission)
    • Apache has a "Allow" directive for that folder. There should be one for /var/www/, you can check default vhost as an example.

    Additionally, you can look at the error.log file (usually located at /var/log/apache2/error.log) which will describe why you are getting the 403 error exactly.

    Finally, you may want to restart apache, just to be sure all that configuration is applied. This can be generally done with /etc/init.d/apache2 restart or systemctl restart apache2. On some system, the script will be called httpd. Just try to figure out.