How to fix the WordPress error ‘Failed to open stream: Permission denied’ caused by file or folder permissions?

Solution: 1 – Fixing WordPress Permission Errors

The issue you’re experiencing is likely related to file and directory permissions. WordPress requires proper permissions to function correctly.

Recommended Permissions

  • Directories: 755
  • Files: 644

Ownership

Ownership depends on your server setup.

Example for Ubuntu with Apache:

owner: apache
group: apache

How to Fix Permissions and Ownership

1. Change Ownership recursively for a directory:

  • sudo chown -R username:group /path/to/wordpress
  • Replaces username and group with the correct user and group for your server.
  • This command updates both files and directories inside the target folder.

2. Set proper directory and file permissions:

  • find /path/to/wordpress/ -type d -exec chmod 755 {} \; # Directories
    find /path/to/wordpress/ -type f -exec chmod 644 {} \; # Files

After applying these changes, WordPress should run without permission-related errors.

Solution: 2 – Check WordPress File and Directory Permissions

The issue might also be caused by incorrect permissions.

Recommended Permissions

Directories: 755 or 750

Files: 644 or 640

Adjust the permissions and test if WordPress runs correctly.

For more details, you can refer to:

URL 1

URL 2

Hope this helps resolve the issue.