How to Fix the SSH “Connection Refused” Error – Kinsta

In computer networks, “localhost” refers to the computer on which a particular program runs. For example, if you are running a program on your own computer (such as a web browser or local web development environment), then your computer is the “localhost”. On the other hand, if you’re talking about a MySQL database that sits on your host’s web server, then your host’s web server is the “localhost” in that scenario.

In the simplest terms, you can essentially think of localhost as meaning “this computer.” Just remember that “this computer” applies to the program, not necessarily to the computer you are physically using.

The localhost typically resolves the IP address to 127.0.0.1, which is also known as the loopback address. Because of its importance, the term “localhost” is a reserved domain name. That means that to avoid confusion, it is impossible to register a domain name that contains “localhost” in the top-level or second-level domain name.

2 Common Situations You’ll Find

localhost with WordPress

There are two areas where you’re likely to encounter the term localhost in relation to WordPress:

Developing/testing WordPress websites

  • in a
  • local environment

  • Configuring/configuring database access to your WordPress site

First, many WordPress developers create something called a “local staging environment” to build WordPress websites. Essentially, this environment mimics a live website, but is completely autonomous on the user’s own computer.

Because the site

only exists on the localhost, it’s easy for developers to test things without fear of breaking something on a live website that might be getting external traffic. Once the site is complete, developers can move the website from its local host environment to a live server environment.

Beyond WordPress development and testing, you may also come across the term localhost if you manually enter or edit your WordPress site’s database credentials. This could happen either when you’re editing your wp-config file.php or working with a plugin.

Next, you will learn a little more about each situation…

How to Install WordPress Locally (Your “Localhost”)

There are many general and WordPress-specific tools you can use to create a local WordPress development environment. With any of these tools, you essentially create a standalone web server on your own computer. Here are some of the most common local development tools for

WordPress:

  • DevKinsta – makes creating and developing local WordPress sites quick and easy. Get a site up and running with Nginx, MariaDB, and more with the click of a button. DevKinsta is free forever! If you have any questions, you can go to their community forum to clarify them.
  • DesktopServer – a WordPress-specific local development solution. In fact, we have a detailed guide on how to install WordPress locally with DesktopServer.
  • MAMP: A cross-platform local development environment that can use Apache and NGINX.
  • XAMPP – a general local development environment that uses the Apache web server.
  • WampServer: A Windows-specific Apache web development environment.

With all these tools, you’ll first need to install and configure them to create your on-premises environment. This is essentially a localhost web server (i.e. it’s a web server that runs on “your computer”). Once your local server environment is running, you can install WordPress on it as you would on your host. Some tools, such as DesktopServer, also include built-in mechanisms to install WordPress quickly.

You will then be able to access your local WordPress site by typing

“localhost” in your browser’s address bar:

What is localhost in web development?
An example of a local development environment

Why your WordPress database is located on localhost in most situations

As you learned at the beginning of this article, “localhost” means the computer on which a program runs.

Here’s why that’s important for

your WordPress site’s database:

In 99% of situations, your WordPress site’s database will sit on the same server as the rest of your WordPress site’s files. As a result, whenever you are editing your wp-config file.php or a plugin asks for your “MySQL hostname” or “MySQL host”, you can enter “localhost”.

For example, this is what the DB_HOST entry in the wp-config.php file looks like for a WordPress installation on Kinsta: Localhost in your wp-config.phpLocalhost file in your file

wp-config.php Similarly, if you are using a plugin like Duplicator to migrate your WordPress website, you can enter “localhost” when the plugin asks you to enter the Host value for your database:

<img src="https://kinsta.com/wp-content/uploads/2017/11/what-is-localhost-3.png" alt="Using localhost in the Duplicator plugin

” />
Using localhost in the plugin

Duplicator In both situations, you’re basically telling WordPress (or a WordPress plugin) to look for the same database from the server where WordPress is located. While you’re unlikely to encounter the term localhost on a daily basis unless you’re a developer, it’s helpful to know how localhost relates to WordPress.

Remember: For an easy way to remember what localhost is, think of phrases like “this computer” or “the computer this program runs on.” It’s that simple!