Apache 403 Forbidden: Reasons and How to Fix It

November 25, 2020

Introduction

Apache is a popular open-source app for running web servers, owing to its reliability and stability. Despite its ease of use, it’s not uncommon to encounter a ‘403 Forbidden’ error after setting up a website using Apache.

In this tutorial, we will go over potential causes of the Apache ‘403 Forbidden’ error and different ways you can fix it.

Apache 403 forbidden: reasons and how to fix it

Prerequisites

  • A user account with root or sudo privileges
  • Access to the command line terminal
  • An installed version of Apache web server

Apache 403 Forbidden: Effects and Possible Causes

The Apache ‘403 Forbidden’ error appears when you try to load a web page with restricted access. Depending on your browser and the website in question, there are different versions of the 403 error message:

      • Forbidden
      • Error 403
      • HTTP Error 403.14 – Forbidden
      • 403 Forbidden
      • HTTP 403
      • Forbidden: You don’t have permission to access the site using this server
      • Error 403 – Forbidden
      • HTTP Error 403 – Forbidden

Example of an Apache 403 forbidden error message.

There are several potential reasons why the Apache 403 error occurs:

      • The first option is a permission error in the webroot directory, where users don’t have access to website files.
      • The second possible reason for a 403 error is missing or incorrect settings in the Apache configuration files.
      • Finally, failing to set up a default directory index also triggers a 403 error message in Apache.

How to Fix ‘403 Forbidden’ in Apache

If you have come across an Apache ‘403 Forbidden’ message, there are several ways to fix it:

Method 1: Setting File Permissions and Ownership

If you suspect the cause of the 403 error to be incorrect file permissions, use:

sudo chmod -R 775 /path/to/webroot/directory

The chmod command sets the execute permission for the webroot directory and read permission for the index.html file.

To change directory ownership, use:

sudo chown -R user:group /path/to/webroot/directory

Where:

      • user is the user account with root privileges on your web server.
      • group is www-data or apache.

Restart the Apache web server for the changes to take effect.

If you are working with Ubuntu, use the following command to restart Apache:

sudo systemctl restart apache2

If you are working with Centos, use:

sudo systemctl restart httpd

Note: If you are having difficulties to restart the Apache service, see our articles: How to Restart Apache on CentOS or How Restart Apache on Ubuntu.


Method 2: Setting Apache Directives

It is possible that the proper require directive is not configured and restricts access to resources. To fix it:

1. Access Apache’s main configuration file. For Ubuntu, use:

sudo nano /etc/apache2/apache2.conf

For Centos, use:

sudo nano /etc/httpd/httpd.conf

2. Once you open the configuration file, scroll down to the following section:

Apache main configuration file

3. If the final line in the <Directory /var/www/> section contains Require all denied, change it to Require all granted.

4. Press Ctrl+X and then Y to save changes to the Apache configuration file.

5. Restart the Apache web server for the changes to take effect. For Ubuntu, use:

sudo systemctl restart apache2

For Centos, use:

sudo systemctl restart httpd

Method 3: Adding a Default Directory Index

When a user visits a URL that requests a directory, the web server looks for a file in the given directory. If the file or any similar files are not found, and directory index listings are disabled, the web server displays the ‘403 Forbidden’ error message.

To fix the issue, add a default directory index.

1. Access Apache’s main configuration file by using:

sudo nano /etc/apache2/apache2.conf

2. Scroll down to find out the default index file name:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml

3. Make sure there is a file in the webroot folder with this name and upload it if it’s missing.

Conclusion

After following this tutorial, you should be able to determine the cause of an Apache ‘403 Forbidden’ error and fix any issues you may find.

Was this article helpful?
YesNo
Aleksandar Kovačević
Aleksandar Kovacevic is an aspiring Technical Writer at phoenixNAP. With a background in both design and writing, he aims to bring a fresh perspective to writing for IT, making complicated concepts easy to understand and approach.
Next you should read
How to Install Apache Hive on Ubuntu
June 23, 2020

This tutorial shows you how to install, configure, and perform basic commands in Apache Hive. Improve your...
Read more
Apache Hadoop Architecture Explained (with Diagrams)
May 25, 2020

Apache Hadoop is the go-to framework for storing and processing big data. This article provides clear-cut...
Read more
How to Set Up Apache Virtual Hosts on Ubuntu 18.04
September 26, 2019

Name-based virtual hosts allow you to have a number of domains with the same IP address. This article...
Read more
How to Install Apache on Ubuntu 18.04
March 22, 2019

This guide will help you install the Apache web server on an Ubuntu Linux 18.04 operating system. Ubuntu...
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.