How to Fix the 403 Forbidden Error in WordPress


How to Fix the 403 Forbidden Error in WordPress

What is a 403 Forbidden Error – Access Denied Error in WordPress?

The 403 Forbidden error is an HTTP status code which appears when we don’t have permissions to access a specific page or a resource on our website, most probably because of some improper configuration of our web server. In most cases, it may take more time to actually identify and find what exactly is causing this 403 forbidden error on WordPress, than fixing the error itself.

In this article, we will go over what exactly the 403 Forbidden Error means when it appears on your WordPress sites, and how to easily fix the 403 forbidden error, access denied in WordPress.

What Causes 403 Forbidden Error in WordPress?

403 forbidden error

When your server permissions don’t allow access to a specific page, The 403 Forbidden error code is shown. When it comes to our WordPress site we can narrow down the appearance of the 403 Forbidden error to a couple of scenarios:

  • 403 Forbidden error when we try to access your WordPress login page (wp-admin)
  • 403 Forbidden error during your WordPress installation
  • 403 Forbidden error when trying to access a page on your site.
  • 403 Forbidden error after migrating your site from another server.

1. Complete Backup of WordPress

Before we start doing anything it is highly recommended to make a complete backup of your WordPress site.

To do this, you will first need to login to your server via SSH.

Next, navigate to your WordPress root directory. For example, it could be located at: /var/www/html/wordpress/.

To make a full archived backup of your whole WordPress site, you can execute the following command:

tar -cpzf wp-backup.tar.gz /var/www/html/wordpress/

Additionally, you will also need to make a backup of your database. Your WordPress database stores all the information about your website like posts, pages, comments, user accounts, plugin configurations etc.

To make a full backup of your database you can use the following command, followed by your database password:

mysqldump -u db_user -p db_name > wp_db_backup.sql

Make sure to change the wp-user and wp-database accordingly with your actual database user and database name.

If you are not sure of your database information that is currently connected to your WordPress site, you can check the wp-config.php file inside your WordPress root directory and look for the following lines:

define('DB_NAME', 'db_name');
define('DB_USER', 'db_user'); 
define('DB_PASSWORD', 'db_password')

Now we have a full backup of our WordPress site and we can move on to fix the 403 Forbidden error in WordPress we are getting.

2. Fixing 403 Forbidden Error in WordPress Caused by Plugins

Fixing 403 Forbidden Error in WordPress Caused by Plugins

One of the reasons for this error could be a faulty plugin. The easiest way to identify if the 403 Forbidden error is caused by a plugin is to temporarily disable all the plugins you have on your WordPress site.

If the error is gone after we disable all the plugins, then we can confirm it is indeed a plugin causing this error. We can then start turning the plugins back on, one at a time, and keep checking when the error appears again, so we can identify the exact plugin that is causing 403 forbidden error.

3. Fix 403 Forbidden Error Caused by File Permissions in WordPress

Fix 403 Forbidden Error Caused by File Permissions in WordPress

The 403 Forbidden error, may also occur due to incorrect file permissions or wrong ownership of your WordPress files and directories. To change the ownership to a given user/group of your WordPress directory, use the following command:

chown www-data:www-data -R /var/www/html/wordpress/

Replace ‘www-data’ with the actual web server user, and ‘/var/www/html/wordpress’ with the actual path of the WordPress installation.

You should also check permission rules for all the files and directories.

All the directories should have their permissions set to 744 or 755.

And all the files should have their permissions set to 640 or 644.

If any file or directory has wrong permissions, you can manually change them. For example, if we want to change the permissions of the wp-content directory to 755, we can use the following command:

chmod 755 wp-content

Be very careful when dealing with file permissions on your server, because you can easily break something if you are not careful enough. If you are not sure what you are doing, it is best to contact your hosting provider to assist you with this matter.

4. Fix 403 Forbidden Error Caused by Corrupt .htaccess File

Fix 403 Forbidden Error Caused by Corrupt .htaccess File

Another possible reason that could lead to this error is a corrupted .htaccess file.

The .htaccess file is located in your WordPress root directory. Navigate to this directory with the following command (alternatively, you can use some FTP client like FileZilla):

cd /var/www/html/wordpress/

Once we have located the .htaccess file, we can temporarily save it under a different name, so we can check if is really this file that is causing the problem. To rename the file, use the following command:

mv .htaccess .htaccess.backup

Now, we should try to load our website and check if the error is gone. If the error is still there, then the problem is not with the .htaccess file and we can safely change it back to its original name with:

mv .htaccess.backup .htaccess

If removing the .htaccess file corrects the 403 Forbidden error, it means the .htaccess file is corrupted. We can then create a new basic .htaccess file containing the following information:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

 

Fixing the 403 Forbidden error on your WordPress site an easy task if you have a WordPress Hosting with us. Feel free to ask our expert Linux Administrators to fix the 403 Forbidden error in WordPress for you, and it will be taken care of immediately. They are available 24×7, so you can get the help you need at any time.

PS. Feel free to share this blog post if you liked it by using the social network shortcuts – you can also leave a comment instead, found under the share buttons.

Tutorials
Install and run DokuWiki the most versatile Wiki on a CentOS 7 VPS
Tutorials
How to Install SugarCRM Community Edition on an Ubuntu 14.04 VPS
Tutorials
How to install and configure JBoss AS with Java and Apache2 as a reverse proxy
  • binasa

    binasabinasa

    Author Reply

    Thankyou for this wondrous post, I am glad I observed this website on yahoo.


Leave a Reply to binasa
Cancel Reply