Skip to content
Hosting Operations10 min read

How to fix 403 forbidden file permissions: Comparison and Best Practices

Compare chmod, chown, and ACL methods to resolve 403 forbidden errors. Practical guide with security best practices for web hosting environments.

Written by Abdul AbrorTechnical Hosting Support Engineer
white and red do not enter signage
On this page

TL;DR — Key takeaways

  • A 403 forbidden error from file permissions means the web server process lacks read or execute access to the requested file or directory path.
  • Use chmod 644 for files and 755 for directories as the baseline; adjust ownership with chown when the web server user doesn't match the file owner.
  • Test permission changes on a single file or staging environment before applying recursively to production directories.
  • Avoid 777 permissions in production environments as they create security vulnerabilities by allowing any user to modify files.
  • Verify the entire directory path has execute permissions, not just the target file, since the web server must traverse parent directories.

A 403 forbidden error caused by file permissions blocks legitimate web traffic when your server configuration is correct but the filesystem denies access to the web server process. This typically occurs after file uploads, server migrations, or manual file operations that change ownership or permission modes.

This guide compares the three primary approaches to resolving permission-based 403 errors: chmod for permission modes, chown for ownership changes, and ACLs for complex multi-user scenarios. You'll learn when to use each method, how to apply them safely, and which approach fits your hosting environment and security requirements.

Understanding 403 Forbidden Permission Errors

A 403 forbidden error indicates the web server successfully located the requested resource but lacks permission to read or serve it. Permission errors occur at the filesystem level before the web server can process the request.

Web servers like Apache and Nginx run under specific user accounts (www-data, apache, nginx, or nobody). These processes must have read permission for files and execute permission for all directories in the path leading to the requested resource.

Three permission components control access: the owner user, the owner group, and all other users. Each component can have read (4), write (2), and execute (1) permissions. Directories require execute permission for traversal even when the web server only needs to read files inside them.

  • Permission denied on index.html blocks that specific file
  • Permission denied on /var/www/html blocks access to everything inside that directory
  • Missing execute permission on /var prevents access to /var/www/html even if that subdirectory has correct permissions

Method 1: Chmod (Changing Permission Modes)

The chmod command modifies read, write, and execute permissions without changing file ownership. This method works when files are already owned by the correct user or when group permissions allow web server access.

Standard web hosting permissions use 644 for files (owner can read/write, group and others can read) and 755 for directories (owner can read/write/execute, group and others can read/execute). The web server reads files and traverses directories using group or other permissions.

Apply chmod when you've uploaded files via FTP, edited files directly on the server, or restored from a backup that reset permissions. This is the safest first troubleshooting step since it doesn't affect ownership.

Test changes on a single file first. For a file: chmod 644 filename.php. For a directory: chmod 755 directoryname. Only use recursive operations after confirming the correct permissions on a test file or directory.

  • Pros: Fast, predictable, preserves ownership, works for most shared hosting scenarios
  • Cons: Ineffective when ownership is wrong, doesn't solve user/group mismatches
  • Use when: Files are owned correctly but permissions are too restrictive (600, 640, or similar)
  • Avoid: Recursive 777 operations that create security holes

Method 2: Chown (Changing File Ownership)

The chown command transfers file ownership to a different user or group. Use this method when files are owned by the wrong account, commonly after root user operations, migrations, or deployments from CI/CD pipelines.

Web servers need files owned by their runtime user or by a user in the same group. Check your web server's user with ps aux | grep -E 'apache|nginx|httpd' or refer to your hosting provider's documentation.

Chown requires root or sudo privileges on most systems. The syntax is chown username:groupname filename. Many shared hosting environments restrict chown access, making this method unavailable without support ticket escalation.

After changing ownership, verify permissions are still appropriate. Ownership change doesn't modify permission modes, so you may need both chown and chmod to fully resolve the issue.

  • Pros: Fixes root-owned files, resolves deployment ownership issues, works with restrictive permission modes
  • Cons: Requires elevated privileges, unavailable in many shared hosting environments, can break file manager access if done incorrectly
  • Use when: Files are owned by root, deployment user, or previous account owner after migration
  • Avoid: Changing ownership of system directories outside your web root

Method 3: Access Control Lists (ACLs)

ACLs extend standard Unix permissions by allowing multiple users and groups to have different permission levels on the same file. This method solves scenarios where both the web server and a deployment user need write access.

Use setfacl to add granular permissions without changing the base owner or mode. For example: setfacl -m u:www-data:rw filename.php grants read and write access to the www-data user while preserving existing ownership.

ACLs are particularly useful in development environments, CI/CD workflows, or when multiple services access the same files. They add complexity and require filesystem support (most modern Linux systems support ACLs on ext4 and xfs).

Check existing ACLs with getfacl filename. Remove ACL entries with setfacl -x rather than modifying base permissions. ACLs persist through permission changes but may not survive file moves or copies depending on the tool used.

  • Pros: Supports multiple users with different permissions, preserves existing ownership and modes, ideal for complex environments
  • Cons: More complex to manage, not supported in all hosting environments, may not persist through all file operations
  • Use when: Multiple users or services need different access levels to the same files
  • Avoid: Simple scenarios where chmod or chown would suffice

Comparison and Recommendation by Use Case

For shared hosting environments, chmod is your primary tool. Shared hosts typically ensure correct ownership, and permission adjustments resolve most 403 errors. Use 644 for files and 755 for directories. If chmod doesn't work, contact support since you likely lack chown privileges.

For VPS and dedicated servers, combine chown and chmod. Start by verifying ownership matches your web server user with ls -la. If ownership is wrong, use chown first, then apply appropriate chmod values. This two-step approach covers both ownership and permission issues.

For development environments and CI/CD workflows, consider ACLs when both a deployment user and web server need write access. ACLs prevent permission conflicts during automated deployments while maintaining security. Fall back to chown with group-based permissions if ACLs add unnecessary complexity.

For production environments, prioritize security. Never use 777 permissions even temporarily. Use 644/755 as your baseline, apply chown when needed, and reserve ACLs for documented multi-user requirements. Always test permission changes in staging first.

  • Shared hosting: chmod 644 (files) and 755 (directories) covers 95% of cases
  • VPS/Dedicated: chown to web server user, then chmod to appropriate modes
  • CI/CD environments: ACLs for multi-user write access, or group-based permissions with proper umask
  • Emergency production fix: chmod on specific files only, document the change, plan a proper ownership review

Safe Testing and Rollback Procedures

Before applying permission changes recursively, test on a single file or directory. Create a test file in the affected directory, apply your permission change, and access it through your browser. This confirms your approach works without risking an entire site.

Document current permissions before making changes. Use ls -la > permissions_backup.txt to capture the current state. For ownership, ls -ln shows numeric user and group IDs which remain valid even if username mappings change.

Apply recursive changes only after single-file validation. Use find commands for precision: find /path -type f -exec chmod 644 {} \; for files and find /path -type d -exec chmod 755 {} \; for directories. This prevents accidentally applying directory permissions to files.

For rollback, use your permissions backup file to restore previous states. If you forgot to capture the initial state, check recently modified files with find /path -mmin -5 to identify changed files, then review your shell history for the exact commands used.

  • Test permission changes on a copy of the site or in a staging environment when available
  • Use version control systems to track configuration file permission requirements
  • Keep a separate session open with working access while testing permission changes
  • Document successful permission patterns in a runbook for future reference

Common Permission Patterns and Security Guidelines

Web root directories typically use 755 permissions to allow directory listing and traversal. Application directories like wp-content/uploads may need 755 or 775 depending on whether the web server writes files directly.

Configuration files containing credentials should use 640 or 600 permissions to prevent unauthorized reading. The web server reads these files at startup or through the application, not through direct web requests, so public read access is unnecessary.

Uploaded content requires write permission for the web server user. Use 755 for upload directories and let the application create files with appropriate permissions. Avoid making the entire web root writable to prevent unauthorized file creation.

Never use 777 permissions in production. This allows any user on the system to read, modify, and execute files, creating security vulnerabilities even on single-user systems due to compromised web applications. Use 775 or group-based permissions if multiple users need write access.

  • Public web files: 644 (files), 755 (directories)
  • Private config files: 640 or 600 with proper ownership
  • Upload directories: 755 (directory), 644 (uploaded files created by application)
  • Executable scripts: 755 only when necessary, 644 for scripts executed by interpreters

Quick troubleshooting checklist

  • Identify the exact file or directory path causing the 403 error from web server error logs
  • Check current permissions with ls -la and verify the web server user with ps aux | grep httpd or nginx
  • Document existing permissions before making changes: ls -la > backup.txt
  • Test permission changes on a single file or staging environment first
  • Apply chmod 644 to files and 755 to directories as the baseline fix
  • If chmod fails, verify ownership and use chown if you have appropriate privileges
  • Test the fix by accessing the previously blocked resource through a browser
  • Apply changes recursively only after validating the single-file fix
  • Review configuration files for permission requirements that differ from defaults
  • Document the final working permissions for future troubleshooting

FAQ

What permissions should I use for web files and directories?

Use 644 for files and 755 for directories as the standard baseline for web hosting. This gives the owner read and write access while allowing the web server to read files and traverse directories. Configuration files with sensitive data should use 640 or 600 to restrict access to the owner and web server group only.

Why does chmod 777 fix the error but create security problems?

Permission mode 777 grants read, write, and execute access to all users on the system. This fixes 403 errors by removing all access restrictions, but it allows any compromised web application or local user account to modify or delete your files. Use 755 for directories and 644 for files instead, which provides web server access without the security risk.

When should I use chown instead of chmod to fix 403 errors?

Use chown when files are owned by the wrong user account, typically after root user operations, server migrations, or deployments. If chmod doesn't resolve the 403 error and ls -la shows files owned by root or a different user than your web server process, changing ownership with chown is required. Most shared hosting environments don't allow chown, so contact support if ownership is incorrect.