Apache 403 Forbidden Bug Fixes: Causes and Workarounds

Introduce

Due to its reliability and stability, Apache is a popular open-source application for running web servers. Although it’s easy to use, it’s not uncommon to encounter a “403 Forbidden” error after setting up a website with Apache.

How to Fix Apache 403 Forbidden Error? In this tutorial, we’ll discuss the potential causes of the Apache 403 Forbidden error and the different ways to fix it.

Prerequisite

  • A user account with root or sudo privileges
  • Access the command-line terminal
  • The version of the Apache web server that has been installed

Apache 403 Forbidden Bug Fix Analysis: Impact and Possible Causes

When you try to load a web page with restricted access, you get an Apache 403 Forbidden ‘ error. 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

There are several potential reasons for Apache 403 errors to occur:

  • The first option is a permission error in the webroot directory, and the user does not have access to the website files.
  • The second possible cause of a 403 error is a missing or incorrect setting in the Apache configuration file.
  • Finally, failing to set a default directory index can also trigger a 403 error message in Apache.

How to fix Apache 403 Forbidden error

If you come across an Apache 403 Forbidden‘ message, there are a few ways to fix it:

Method 1: Set file permissions and ownership

How to fix Apache 403 Forbidden error: If you suspect that the cause of the 403 error is incorrect file permissions, use:

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

The chmod command set is a file with execution and read permissions for the root directory of the index.html.

To change catalog ownership, use:

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

Thereinto:

  • user is a 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’re using Ubuntu, restart Apache with the following command:

sudo systemctl restart apache2

If you’re using CentOS, use:

sudo systemctl restart httpd

Note: If you’re having trouble restarting your Apache service, see our articles: How to restart Apache on CentOS or how to restart Apache on Ubuntu.

Method 2: Set up Apache directives

Apache 403 Forbidden bug fix: Require directives may not be configured correctly and restrict access to resources. To solve this problem:

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 have your profile open, scroll down to the following sections:

3. If the last line of the /var/www/> section of that < directory contains Require all denied, change it to Require all granted.

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

5. How to fix the Apache 403 Formal error – 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: Add a default catalog index

Apache 403 Forbidden bug fix: When a user accesses the URL of a request directory, the web server looks for a file in the given directory. If the file or any similar file is not found, and the directory index list is disabled, the web server displays a “403 Forbidden” error message.

To resolve this issue, add a default catalog index.

1. Use the following command to access Apache’s main configuration file:

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 with the same name in the webroot folder and upload it if not.

Conclusion

How to Fix Apache 403 Forbidden Error? After following this tutorial, you should be able to identify the cause of the Apache 403 Forbidden’s error and fix any issues you may find.

If you want to know more about the 403 Forbidden error, read our article The 403 Forbidden Error Solution – What It Is and How to Fix It.