403 Forbidden Error on PHP Sites: What It Means and How to Fix It

403 Forbidden error on a PHP site caused by permissions or server configuration

Quick answer: A 403 Forbidden means the server received the request but refused access. On PHP sites, the most common causes are wrong permissions (normally 755 for folders and 644 for files), the wrong file owner, Deny or Require rules in .htaccess, a folder with no index file and directory listing turned off, or a block by a firewall or ModSecurity. The web server's error log usually names the exact cause.

The 403 Forbidden error is one of the most common problems on PHP sites, especially after moving to a new server, uploading files with the wrong permissions or changing security rules.

Unlike a 404, where the page doesn't exist, a 403 means the server understood the request but refused to serve it. The file is usually there; something is stopping the server from delivering it.

What is a 403 Forbidden error?

The 403 status code is returned when the server blocks access to a file, folder or resource. On PHP sites it is almost always caused by one of three things: file system permissions, web server configuration, or a security layer (firewall, WAF, hosting protection).

Don't confuse it with 401 Unauthorized, which means "you need to log in": a 403 means "even if you are logged in, you can't have this".

Common causes of a 403 on PHP sites

1. Wrong file and folder permissions

The web server needs to read files and enter folders. The usual safe values:

  • Folders: 755 (owner can write; everyone can enter and read);
  • Files, including PHP: 644 (owner can write; everyone can read).

A folder at 700 or a file at 600 owned by another user produces a 403. Never "fix" it with 777: that lets any process on the server change your files.

2. Wrong owner

After uploading files as root or another user, the web server user (www-data on Debian/Ubuntu, apache or nginx on RHEL and Amazon Linux) may not be able to read them, or to write in folders like uploads/ or cache/.

3. .htaccess rules blocking access

A restrictive or wrong rule in .htaccess gives a 403 immediately. Common examples:

# Apache 2.4
Require all denied

# Old Apache 2.2 syntax, still found in many files
Deny from all

# Blocks by IP that also catch legitimate visitors
Require not ip 203.0.113.0/24

These rules also apply to every subfolder, so a .htaccess in a parent folder can block a whole section of the site.

4. No index file and directory listing disabled

When a URL points to a folder without index.php or index.html, and directory listing is disabled (as it should be), Apache returns 403. Check the file name (it is case-sensitive on Linux: Index.php isn't index.php) and the DirectoryIndex setting.

5. Firewall, WAF or hosting security

ModSecurity, Cloudflare WAF, Imunify360 and other protections can block IPs, user agents, countries or requests that look like attacks, for example a form with HTML or SQL in it. These blocks look like a normal 403.

6. SELinux on RHEL, CentOS, Rocky and Amazon Linux

If permissions look right but Apache still returns 403, SELinux may be denying access to files with the wrong security context, typically after copying files from a home folder.

7. Server configuration

A <Directory> block in the Apache configuration that doesn't allow access to the folder where the site lives, or an Nginx deny all; in a location block, gives a 403 for everything inside.

How to find the cause

Read the web server's error log

It usually names the exact reason:

# Debian / Ubuntu
sudo tail -n 30 /var/log/apache2/error.log
# RHEL / Amazon Linux
sudo tail -n 30 /var/log/httpd/error_log
# Nginx
sudo tail -n 30 /var/log/nginx/error.log
MessageCause
AH01630: client denied by server configurationA Require/Deny rule in .htaccess or the Apache config
AH00035: access to / denied ... because search permissions are missingA folder in the path isn't executable (needs 755)
(13)Permission deniedFile permissions, owner or SELinux
AH01276: Cannot serve directory ... No matching DirectoryIndexNo index file in the folder
ModSecurity: Access denied with code 403Blocked by the WAF; the line shows the rule ID

On shared hosting (cPanel, Plesk), look for "Errors" or "Error log" in the control panel.

Check permissions and owner

ls -la /var/www/example.com/public
namei -l /var/www/example.com/public/index.php   # shows permissions of every folder in the path

Test without the .htaccess

Rename .htaccess to .htaccess_old and reload the page. If the 403 disappears, the problem is one of its rules; restore the file and remove rules one at a time to find it.

How to fix a 403 Forbidden on a PHP site

1. Fix permissions

cd /var/www/example.com/public
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

2. Fix the owner

# Debian / Ubuntu
sudo chown -R www-data:www-data /var/www/example.com/public
# RHEL / Amazon Linux
sudo chown -R apache:apache /var/www/example.com/public

On servers where you deploy as your own user, a common setup is your user as owner and the web server group with write access only on uploads/ and cache/.

3. Fix the SELinux context

sudo restorecon -Rv /var/www/example.com
# folders PHP must write to:
sudo chcon -R -t httpd_sys_rw_content_t /var/www/example.com/public/uploads

For a permanent rule on writable folders, use semanage fcontext followed by restorecon. Don't disable SELinux to make the error go away.

4. Make sure an index file exists

DirectoryIndex index.php index.html
Options -Indexes

Options -Indexes keeps directory listing off, which is the safe default.

5. Review .htaccess and server rules

Remove or narrow rules that block more than intended, and make sure the Apache <Directory> block for your site allows access (Require all granted) and, if you use .htaccess, has AllowOverride All (or the specific overrides you need). Test with sudo apachectl configtest before reloading. The .htaccess generator helps write clean rules.

6. Check firewall and WAF blocks

If the log shows ModSecurity, find the rule ID and ask your host to whitelist it for that URL, rather than turning the WAF off. In Cloudflare, check Security > Events to see what was blocked and why. Make sure your own IP isn't blocked by fail2ban or the hosting firewall.

403 vs. 404 vs. 500

CodeMeaning
403 ForbiddenThe resource exists, but access is refused
404 Not FoundThe resource doesn't exist at that URL
500 Internal Server ErrorThe server or the application failed while processing

For 500 errors, see how to find the cause of a PHP 500 error in the logs; for gateway errors, 502 Bad Gateway.

How to avoid 403 errors in the future

  • Use a standard permission scheme (755/644) and a deploy process that applies it;
  • Avoid broad blocking rules in .htaccess;
  • Keep error logs enabled;
  • Test changes in staging before publishing;
  • Watch the WAF and firewall logs after enabling new rules.

Conclusion

A 403 Forbidden is an access problem, not a missing file. On PHP sites it almost always comes from permissions, ownership, an .htaccess or server rule, or a security layer. Start with the error log: it usually tells you which one, and the fix takes minutes.

Frequently asked questions about 403 errors

What permissions should a PHP site use?

755 for folders and 644 for files. Only folders where PHP must write (uploads, cache) need write access for the web server user.

Should I use chmod 777 to fix a 403?

No. It is a security risk and rarely the real fix. Correct the owner and use 755/644.

Why do I get 403 only on some pages?

Usually a rule in an .htaccess inside that folder, a WAF rule triggered by something in the URL or form, or files in that folder with different permissions.

Can a 403 come from Cloudflare?

Yes. Cloudflare's firewall rules, bot protection and country blocks return a 403 page. Check Security > Events in the Cloudflare dashboard.

Is 403 the same as 401?

No. 401 means authentication is missing or invalid; 403 means access is refused even with authentication.

More in Web troubleshooting