File permissions in WordPress are an important factor in safeguarding the website against attacks. When the settings of the files and folders are too loose, the hackers can get an opportunity to change the website content and even inject some malware.
The file that needs special care is wp-config.php. It includes some configuration settings that include the credentials with which WordPress communicates with its database. If an intruder gets hold of this file, he may have some more than just affecting the site’s appearance.
Protecting your WordPress site includes giving the proper file permissions and protecting your sensitive configuration files from any access. This tutorial will help you do that without interfering with your website’s functionality.
Table of Contents
WordPress File Permissions and Their Significance
File permissions in WordPress regulate who is allowed to perform operations such as reading, writing, modifying or executing a particular file, as well as who has permission to access certain directories on your host server.
Understanding Read, Write and Execute Permissions
The file permissions in Linux include three main categories:
- Read (4): Gives permission to a user to read a file or list its contents in case of a directory.
- Write (2): Gives permission to a user to modify a file or create/deletes files from a directory.
- Execute (1): Gives permission to a user to execute a file or access a directory.
These permissions are identified by three digits, one for each category of the owner, group, and others.
For instance, permission 755 means that the owner has read, write, and execute permissions while group and others have read and execute permissions. Permission 644 will give the owner read and write permission while giving read permission to everyone else.
How Incorrect File Permissions Make WordPress Sites Vulnerable
Incorrect file permissions can make a WordPress site vulnerable to different security threats. This is because any unauthorized user will be able to alter vital files, making it easy for them to inject malicious code.
Too many permissions will also make it easy for scripts or applications that have been compromised to alter files that they are not supposed to have access to. On the other hand, permissions that are too restrictive may prevent WordPress from uploading media, installing uinstalling updates or performing other essential operations.
WordPress File Permissions – What are the Recommendations?
There isn’t any specific set of permissions that apply to all WordPress sites out there. The right configuration may vary depending on file ownership and the web server PHP handling environment.
Here are some common configurations:
Permissions for Files on WordPress
Regular files in WordPress usually have permissions of 644. This gives permission to the owner to read and write files, whereas other users are able to read them only.
A more stringent file setting may be required for important files. For instance, wp-config.php could have settings of 400 or 440 depending on the web server.
Recommended Permissions for WordPress Folders
Folks often assign 755 permissions to WordPress folders. The folder owner has the ability to read, write and execute the folder, and all others have the ability to read and execute without making any changes to the folder.
In certain cases, you can assign 750 permissions in your hosting environment.
Reasons Why You Should Not Use Permission 777
Permission 777 gives all individuals the rights to read, write, and execute files/directories. The reason why it creates security vulnerabilities is that other users or processes could potentially modify the files.
Do not use permission 777 as a means of solving permission problems related to WordPress. One should determine the problem regarding ownership or access and fix it by solving the issue of the respective file or directory. If you are not sure about it, get in touch with your web host before any modifications.
Why Is wp-config.php File So Important to Protect?
wp-config.php file is among the most sensitive files within a WordPress site. The file connects WordPress with its database and keeps the critical configuration details which are necessary for running the website.
Sensitive Data Within wp-config.php
The file can contain:
- Prefix of WordPress database tables.
- Authenticating keys and security salts.
- Database name, username, and password.
- Database host information.
- Various additional website configurations.
If the wrong hands get hold of these, it is possible that they will use them to gain access to your database or website.
What Will an Attacker Do Once He Gains Access to wp-config.php?
The hacker that will have gained the database credentials will try to establish a connection to the database so as to access the website data. The attacker can also alter data, make illegal administrator accounts, or affect how websites work based on the permissions given to the database user.
Authentication keys and security salts might compromise the already existing security measures as well. That is why limiting access to wp-config.php file should be one of your priorities when it comes to WordPress security.
How to Secure Your WordPress File Permissions
Create a full backup of your website and database before modifying the permissions. The wrong setting can block WordPress access to critical files; make sure that you have the means of recovering from this.
1. Setting File Permissions Using cPanel or FTP Client
Your file permissions can be set using the cPanel File Manager tool or the FTP client like FileZilla.
For changing the permissions via cPanel:
- Login to cPanel account.
- Go to File Manager and browse to the directory where WordPress is installed.
- Select the file or directory whose permissions you wish to change.
- Right-click on it and choose Change Permissions.
- Add the appropriate permissions number or choose the access options.
- Click the “Save Changes” button and make sure that your website is working properly.
Using this technique, you should not assign the same permissions for all files and directories. Regular files, directories, and configuration files may need separate permissions.
2. Changing File Permissions via SSH
Example:
| Â chmod 644 wp-config.php |
It will grant permissions for reading and writing for the file owner and permission for reading for all others. However, due to sensitive data stored in wp-config.php, a stricter permission level like 400 or 440 would be more suitable.
You can also use the following commands to set common permissions for ordinary WordPress files and directories:
| find /path/to/wordpress/ -type d -exec chmod 755 {} \; |
| find /path/to/wordpress/ -type f -exec chmod 644 {} \; |
Use the correct path of your installation instead of /path/to/wordpress/. The above commands set permissions recursively, and hence they should be executed after thoroughly understanding what they do. It is especially important to look into sensitive files like wp-config.php file and impose restrictions on them after that.
How to Protect Your WordPress wp-config.php File
File permissions are very important, but there are other measures you could take to further limit access to the WordPress configuration file.
1. Limiting Access to wp-config.php
Access to the wp-config.php file should be limited to just its owner and processes.
400 or 440 permissions depend on where you are hosting the files. These permission settings give better security compared to the 644 permission setting.
Nevertheless, ensure your web server can still read the file once the changes have been made. In case WordPress shows an error in connection to the configuration or database, undo the changes and revert to the previous permission setting.
2. Move wp-config.php Outside the Public Web Root
WordPress supports placing wp-config.php one directory above the WordPress installation. This will give you one more level of security since the file won’t be inside the public website directory.
For example, if your WordPress files are stored in:
| Â Â /home/username/public_html/ |
You may be able to place the configuration file in:
| Â Â /home/username/wp-config.php |
Make sure that your hosting environment allows such an arrangement and WordPress can find the file. Make a backup copy of the original file before moving the file and then test the website.
Moving the file is just another security measure, and not a substitute for strict permissions and configurations of the server.
3. Prevent Direct Access to wp-config.php from Web Browsers
If your website runs on an Apache server, you can use an .htaccess rule to deny direct HTTP requests to wp-config.php.
Include the following directive in the .htaccess file:
| <Files “wp-config.php”> Require all denied </Files> |
This prevents visitors from requesting the configuration file directly through a browser. Place the rule outside the WordPress-managed rewrite section where possible.
The directive shown is for Apache 2.4. Nginx servers require a different server-level configuration, so contact your hosting provider if you use Nginx or are unsure which web server your website runs on.
4. Disable File Editing from the WordPress Dashboard
WordPress allows administrators to edit plugin and theme PHP files through the dashboard by default. If an intruder gets hold of an admin account, this option may offer yet another avenue for getting a malicious code onto the site.
The following line can be added to wp-config.php in order to turn off the native file editor feature:
| Â define( ‘DISALLOW_FILE_EDIT’, true ); |
It will disable the native file editing feature for themes and plugins from the dashboard. However, this is not a fail-safe against all types of file modifications but limits another avenue that attackers could use.
Common File Permission Mistakes to Avoid
Once you have changed your WordPress file permissions, there are some common mistakes that may make your site vulnerable.
- Files & directories with permission 777: It provides write permissions to all unnecessary users and poses a security threat.
- Using similar permission in all cases: There is a difference between permission for files and directories.
- Allowing wp-config.php permission without restrictions: Do not provide unnecessary read/write permissions to this important file.
- Overlooking ownership of the files: Even if you have correct permission numbers, having the wrong ownership of the files might still be a problem.
- Using restrictive settings too much: Restrictions on permissions may stop WordPress from accessing important files and result in website issues.
- Permissions changes without a backup: You should always take a backup of your site before making any permission changes.
How to Find out Whether Your WordPress File Permissions Are Secure
Checking file permissions frequently will assist you in discovering unnecessary accesses.
It is recommended that you review your WordPress installation via cPanel File Manager, FTP software, or SSH first. Regular files, directories, and the configuration files need to be examined independently.
Pay particular attention to wp-config.php, the wp-admin and wp-includes directories, and folders within wp-content. Note any unusual changes in permission and strange files and folders that offer unwanted write permission.
In addition to that, ensure that the ownership of files is correct and also check that all major functionalities on your website work properly after making these changes. This includes checking if your dashboard loads fine and if you can upload media and make required updates on WordPress.
If you find unexpected permission changes or strange files, investigate them rather than changing their permissions. These can be signs of an overall security issue that needs malware detection and more investigation.
Conclusion
Proper security of WordPress file permissions protects against any unauthorized people or operations accessing or altering your website’s files. With proper file permissions and wp-config.php restriction along with restricting unnecessary file editing on dashboard, many security vulnerabilities can be avoided.
Nonetheless, file permissions can never be relied on to provide absolute safety for your website. Regular WordPress updates, strong administrator passwords, reliable backups and continuous security monitoring are also important.
Are You Looking for Reliable WordPress Hosting?
The hosting environment is important in terms of your site’s security. If you use WordPress for your website, at HarmonWeb, you will be provided with quality WordPress hosting that will fulfill the needs of your website.


