Technical
Security, Web Development, Web Hosting, WordPress

Fix or Properly Set WordPress Directory and File Permissions

Craig Marolf
Web Developer and Marketing Strategist
Published on October 22, 2024
By Craig Marolf in Technical

Share

Setting the proper permissions for WordPress directories and files is crucial for both security and functionality. The permissions need to be set in a way that allows WordPress to function correctly while minimizing security risks. You need to access the command line interface and set the directory permissions to 755 and the file permissions to 644.

Directories (like /wp-content, /wp-includes, etc.) will have the permissions set to 755. The 755 permission allows the owner to read, write, and execute. Group and others can read and execute, but not write. This is typically safe and allows the web server to access these directories as needed. Subdirectories like /wp-content/uploads/ and other directories within /wp-content where files are dynamically written should also have 755 permissions. This ensures that WordPress can upload and manage files properly.

File Permissions

Files (like index.php, wp-config.php, etc.) will have the Permissions set to 644. The 644 permission allows the owner to read and write, while group and others can only read. This is typically safe and prevents unauthorized users from modifying files.

Additional Security for the Config File (optional but recommended)

The wp-config.php file contains sensitive information like database credentials. Setting it to 440 or 400 restricts it so that only the file owner can read it, providing an extra layer of security.

Setting Permissions

Set Directory Permissions (755):

find /path/to/your/wordpress/installation/ -type d -exec chmod 755 {} \;

Set File Permissions (644):

find /path/to/your/wordpress/installation/ -type f -exec chmod 644 {} \;

Set File Permissions (440):

chmod 440 /path/to/your/wordpress/installation/wp-config.php

Setting File Ownership

Ensure that your WordPress files are owned by the user under which your web server (like Apache or Nginx) runs. This is typically www-data, apache, or nginx depending on your server setup.

Set Ownership:

sudo chown -R www-data:www-data /path/to/your/wordpress/installation/

Security Considerations

Avoid 777 Permissions: Never set any WordPress directory or file to 777, as this allows anyone to read, write, and execute, which poses a significant security risk.

Regular Audits: Regularly audit your file permissions and server configurations to ensure that they adhere to best practices.

By following these guidelines, you’ll ensure that your WordPress installation remains secure while functioning properly.