In this article, you will learn how to manually update the WordPress application domain name using WordPress CLI.

Tip:

Click Here if you would like to know what domains are.

At Cloudways, when you add your domain to take your site live, it automatically updates your domain name in the WordPress database, but if you want to update the WordPress application domain name manually, then you may continue reading this article.

WP-CLI is pre-installed on all servers deployed on Cloudways. The steps below will demonstrate how you can operate WP-CLI and update the password.

What is WordPress CLI?

WP-CLI is a command-line interface for WordPress.It is a set of command-line tools for managing WordPress installations on a server. It allows the WordPress admin users to carry out different administrative tasks without actually using a web browser. This management through the command-line interface enables users to take care of their WordPress websites by executing a set of defined commands. The scope of the tasks mainly includes upgrades, database backups, publishment of new posts, etc.

How to Manually Update the Domain

Here are a few simple steps to manually update the domain.

Step# 1

First of all, you need to connect to your server remotely via SSH so you can use WP-CLI.

If you would like to know what is SSH and why it is used, then Click Here to find out. In this example, we are using Master Credentials to access the server remotely.

You can connect to your server via SSH in two ways, so choose your preferred option from the below options. You can also click on the hyperlink text of bullet points to learn about connecting remotely to the server.

In this example, we have used an SSH client named PuTTY. You will see a similar window after successful connection as shown below:

Step# 2

Now, you need to go to that specific directory where your webroot is located. In other words, where your wp-config.php file is located else, WP-CLI will not work. By default, it is in the public_html directory and we will also follow the default path to operate WP-CLI in this example. Enter a command mentioned below to go into the public_html folder.

cd applications/<your_application_name>/public_html/

Important

Angle brackets are included to indicate the positions of your inputs so make sure to remove the angle brackets. Your application name is the same as your Database name (DB name). Click Here to find out where your application name is located.

You will see a similar window after running the above command successfully.

Step# 3

You may start using WP-CLI once you are in the public_html directory.

For instance, if you would like to change the WordPress domain from http://mysite.test to http://mysite.com, then the command below will replace one domain with another and save changes in the database.

wp search-replace <old domain> <new domain>

For example: wp search-replace mysite.test mysite.com

You will see a success message at the end once changes are made in the database.

How to view data changes/replacements using this tool before saving in the database?

The --dry-run switch is one of the most helpful flags of WP search-replace. This flag replaces the string with another one but does not save it in the database or, in other words, shows you a preview of the changes that can be made if run without a flag of --dry-run. This flag can be applied at the end of the above command.

wp search-replace <old domain> <new domain> --dry-run

For example: wp search-replace mysite.test mysite.com –dry-run

Important

The wp search-replace function is somewhat peculiar in its case sensitivity. For best results, match cases exactly and search for other capitalization instances using the --dry-run option. For instance, this searches and replace function entertains the string “Bar” and “bar” differently because of being case sensitive.

Source: WordPress CLI

Now you have learned how to change the domain name on WordPress using WordPress CLI.

That’s it! We hope this article was helpful. If you need any help, then feel free to search your query on Cloudways Support Center or contact us via chat (Need a Hand > Send us a Message). Alternatively, you can also create a support ticket.

Did this answer your question?