How to Fix the WordPress Loopback Error?

Wordpress Logo

Introduction

WordPress is a very powerful website content management system that is used by millions. Sometimes the application will show errors that will make you scratch your head, such as the common WordPress loopback error that you may see when it runs a site health check.

How do I Know if I Have This Error?

The error usually pops up on the first page when you logon to the administrative dashboard of your WordPress site. However, you can also check for this error within the administrative dashboard of your WordPress installation. Once you are logged into the dashboard, hover over the Tools menu. When the menu appears, click on Site Health. If you have the error you will see a message that states “Your site could not complete a loopback request” similar to the one in the screenshot below.

Wordpress Loopback Error in the Admin Dashboard

What is a Loopback request?

A loopback request is simply a request that WordPress is trying to make to itself. Loopback requests are used to run scheduled events (wp-cron.php). Loopback requests need to function correctly in order to ensure your website remains stable.

What caused the Error?

I was running WordPress in a Docker container. So when WordPress tried to loopback to itself via a domain name, the request didn’t make it back to the Docker container. This was because the domain name wasn’t listed in the /etc/hosts file.

Solution

Login to your website using SSH with your favorite terminal application such as PuTTY. Once you are logged in you will want to nano /etc/hosts to open up your servers host file. It should look similar to the screenshot below.

How to Fix the WordPress Loopback Error? 1

Add the following line to the bottom of your hosts file. Make sure to change yourdomain.com to your website domain.

127.0.0.1 yourdomain.com

Once you add that line, you can type ctrl+x. You will then be asked if you want to save your file, type y for yes.

You are not required to reboot your system.

What about WordPress Docker Containers?

Docker is how I was exposed to WordPress loopback error in the first place. When using WordPress in a Docker Container, the loopback error becomes more of a Docker problem rather than a WordPress problem. However, if you are running WordPress via a docker run command (rather than using Docker Compose), then you wont be able to make permanent changes to the container.

Luckily, Docker has an easy solution to this problem. The --add-host flag. When added to a docker run command this flag will allow Docker to add an entry in the /etc/hosts file within the container that you are trying to run.

Simply add this flag to your docker run command. The flag is used like this --add-host yourdomain.com:127.0.0.1. 127.0.0.1 being the host that you want to forward yourdomain.com to, in this case.

Below is an example of a docker run command for WordPress that contains the --add-host flag.

docker run -d \
--name wordpress \
-p 8080:80 \
--add-host yourdomain.com:127.0.0.1 \
wordpress

Success

Now that you have changed your /etc/hosts file, you can go back into the administrative backed of your WordPress installation to check your site health. If you are successful, then you will be presented with the following message “Your site can perform loopback requests“. It should look similar to the screenshot below.

How to Fix the WordPress Loopback Error? 2

That it! If all goes well, the wordpress loopback error will disappear and you can get back to managing your site content.

I hope this post helped you solve the WordPress loopback error. If you have any questions or comments about this post, feel free to leave a comment below.

The post, How to Fix the WordPress Loopback Error?, first appeared on Codeopolis.

2 Comments

Leave a Reply

Your email address will not be published.


*