Skip to main content

Troubleshooting '403 Forbidden' Errors in Hostinger public_html Directory

 Few server responses are as frustrating to a developer as the HTTP 403 Forbidden error. One minute your application is deploying smoothly; the next, you are locked out of your own public_html directory.

On Hostinger’s infrastructure (which typically runs on a hardened OpenLiteSpeed or Apache stack via hPanel), a sudden 403 error rarely implies a server outage. Instead, it indicates that the web server is functioning correctly but explicitly refusing to authorize the request.

This guide provides a rigorous technical breakdown of why this happens in the Hostinger environment and offers direct, command-line, and configuration-level solutions to resolve it.

The Anatomy of a 403 Forbidden Error

Before executing fixes, it is vital to understand the root cause. When a browser requests a resource, the Apache (or OpenLiteSpeed) process checks two primary authorization layers:

  1. File System Permissions: Does the operating system user running the web server have the correct bits set to read/execute the file?
  2. Access Control Lists (ACLs): Do the configuration files (httpd.conf or .htaccess) explicitly deny access based on IP, user agent, or logic rules?

In the Hostinger hPanel ecosystem, 90% of 403 errors stem from two specific issues: permission bit rot (often occurring after a migration or plugin update) or a corrupted .htaccess file.

Step 1: Diagnosing the .htaccess File

The .htaccess (Hypertext Access) file allows decentralized management of web server configuration. It is powerful but brittle. A single syntax error, a rogue character, or a deprecated directive introduced by a security plugin can trigger a site-wide 403 lock.

The Isolation Test

The fastest way to confirm if .htaccess is the culprit is to disable it.

  1. Log in to your Hostinger account and open the File Manager (or connect via FTP/SFTP).
  2. Navigate to public_html.
  3. Rename .htaccess to .htaccess_backup.

If the site immediately loads (likely without styling or working sub-pages), the issue lies within the configuration syntax.

The Fix: restoring a clean Configuration

If the isolation test worked, do not simply revert to the old file. Create a new .htaccess file and input the standard routing rules.

If you are running WordPress, use the standard Apache rewrite rules below. This configuration uses mod_rewrite to handle permalinks efficiently.

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Note: If you are running a custom PHP application (Laravel, Symfony) or a React app served via Apache, ensure your rewrite rules point all traffic to your entry point (usually index.php or index.html) to avoid directory listing denials.

Step 2: Correcting Linux File Permissions (The 755/644 Rule)

If the .htaccess fix fails, the issue is almost certainly permission-based.

Linux permissions are defined by three digits (e.g., 755), representing OwnerGroup, and World.

  • Read (4)
  • Write (2)
  • Execute (1)

Hostinger’s security configuration requires specific permissions. If you set permissions too loose (e.g., 777 - read/write/execute for everyone), the server’s security modules (like suPHP or hardened OLS) will block execution to prevent privilege escalation attacks. This results in a 403.

The Correct Hierarchy

  • Directories: Must be 755 (Owner can write; Group/World can only read/execute).
  • Files: Must be 644 (Owner can write; Group/World can only read).

The Fix: Recursive Permission Reset via SSH

While hPanel offers a "Fix File Ownership" button, a Principal Engineer approach requires precision. Connect to your server via SSH to fix this recursively and accurately.

1. Access the terminal: Use your terminal or the SSH Access feature in hPanel.

2. Navigate to the web root:

cd domains/yourdomain.com/public_html

3. Fix Directory Permissions (755): This command finds all items that are directories (-type d) and sets permissions to 755.

find . -type d -exec chmod 755 {} \;

4. Fix File Permissions (644): This command finds all items that are files (-type f) and sets permissions to 644.

find . -type f -exec chmod 644 {} \;

Warning: Be extremely careful not to run chmod -R 777 .. This exposes your file system to write access by any process and will trigger immediate server-level blocking.

Step 3: Handling "Options -Indexes" and Missing Index Files

If your permissions are correct and your .htaccess is clean, you may be hitting a directory listing block.

By default, modern Apache configurations include Options -Indexes. This directive prevents the server from listing all files in a directory if no default index file is found. If you have a folder named /images but no index.php or index.html inside it, visiting yourdomain.com/images will throw a 403 error.

The Fix

  1. Ensure an Entry Point Exists: Verify that public_html contains an index.php or index.html file. (Note: Linux is case-sensitive; Index.php will not work).
  2. Allow Listing (Dev Environments Only): If you intentionally want to list files, add this to your .htaccess:
Options +Indexes

Advanced Scenario: ModSecurity and WAF False Positives

Hostinger implements a Web Application Firewall (WAF) and ModSecurity rules to filter malicious traffic. Occasionally, a legitimate request containing code snippets, SQL keywords, or suspicious strings in the URL parameters is flagged as an attack.

When this happens, the server returns a 403 Forbidden to protect the application.

Diagnosing WAF Blocks

Check the error_log located in your public_html directory (or via hPanel > Logs). Look for entries labeled ModSecurity: Access denied.

[Fri Oct 27 10:00:00.123456 2023] [:error] [pid 12345] [client 192.168.1.1] ModSecurity: Access denied with code 403 (phase 2). Pattern match "..." at ARGS:content.

If you confirm a false positive:

  1. Short term: Disable ModSecurity in hPanel (Security > ModSecurity) to confirm the diagnosis.
  2. Long term: Do not leave it disabled. Refactor the request triggering the rule or contact Hostinger support to whitelist the specific rule ID.

Summary of Resolution Path

Troubleshooting a 403 error is a process of elimination. Follow this prioritized workflow to minimize downtime:

  1. Check the logs: View error_log for specific Access denied messages.
  2. Isolate .htaccess: Rename the file to rule out bad rewrite rules.
  3. Reset Permissions: strictly enforce 755 for folders and 644 for files using SSH.
  4. Verify Index: Ensure an index.php or index.html exists in the root.

By adhering to strict permission hierarchies and maintaining clean Apache configurations, you ensure your Hostinger environment remains secure and accessible.