How to Fix 403 Forbidden Error in Apache?

A 403 Forbidden error in Apache indicates that the server understands the request but refuses to authorize it. This article provides a comprehensive troubleshooting guide to resolve this issue by examining file permissions, directory configurations, .htaccess restrictions, and security modules like SELinux or ModSecurity. By following these structured steps, administrators can quickly identify the root cause and restore access to their web applications.

1. Correct File and Directory Permissions

The most common cause of a 403 Forbidden error is incorrect file or folder permissions. Apache must have the necessary rights to read the files and execute the directories.

To reset permissions across your web root (commonly /var/www/html), run the following commands in your terminal:

find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;

Additionally, ensure that the Apache user (usually www-data, apache, or nobody) owns the files, or at least belongs to the group that has read access.

2. Update Apache Configuration Directives

Changes in Apache syntax between versions (especially from 2.2 to 2.4) frequently trigger authorization errors. Ensure your configuration file (e.g., httpd.conf or apache2.conf) explicitly grants access to your web directory.

For Apache 2.4 and newer, use the Require all granted directive:

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Note: If you are upgrading from an older version, remove outdated lines like Order allow,deny and Allow from all, as they can conflict with the new syntax.

3. Inspect the .htaccess File

A misconfigured .htaccess file inside your website’s root directory can override server settings and block access.

4. Verify Directory Index Settings

If a user attempts to access a directory (e.g., example.com/images/) instead of a specific file, Apache will try to serve an index file. If directory browsing is disabled and no index file exists, a 403 error occurs.

DirectoryIndex index.php index.html

5. Check SELinux and Security Modules

If permissions and configurations look perfect but the error persists, security software might be blocking Apache.

chcon -R -t httpd_sys_content_t /var/www/html