Lorenzo Sfienti

How to change WordPress Domain URL with WP-CLI Tool

Are you looking to change your WordPress domain URL but unsure about the technical process involved? Fear not! In this comprehensive guide, we will walk you through the steps to change your WordPress domain URL using the WP-CLI Tool. With this powerful command-line interface, you can effortlessly migrate your website to a new domain while preserving all your content, settings, and SEO rankings.

Why Use the WP-CLI Tool for Changing WordPress Domain URL?

Changing a WordPress domain URL manually can be a daunting task, especially if you have a large website with numerous pages and posts. The WP-CLI Tool simplifies this process by allowing you to perform the necessary changes using simple commands. With just a few keystrokes, you can update your domain URL and ensure a smooth transition for your website visitors.


Before we dive into the steps, let’s ensure you have everything you need to change your WordPress domain URL with the WP-CLI Tool:

  1. WordPress Hosting: Ensure that your WordPress website is hosted on a server that supports WP-CLI. Many popular hosting providers, such as Bluehost, SiteGround, and WP Engine, offer WP-CLI support.
  2. SSH Access: You need SSH access to your WordPress hosting server to use the WP-CLI Tool. If you’re not sure how to connect via SSH, contact your hosting provider for assistance.

Step-by-Step Guide to Changing WordPress Domain URL

Now that you have met the prerequisites, let’s dive into the step-by-step process of changing your WordPress domain URL using the WP-CLI Tool:

  1. Step 1: Connect to your WordPress Hosting Server via SSH
    • Open your preferred SSH client (e.g., Terminal for macOS and Linux, PuTTY for Windows).
    • Enter the SSH command provided by your hosting provider, along with your login credentials, to establish a secure connection.
  2. Step 2: Navigate to Your WordPress Installation Directory
    • Once connected via SSH, navigate to the root directory of your WordPress installation. This is typically the public_html directory.
      cd /path/to/your/wordpress/installation
  3. Step 3: Verify WP-CLI Tool Availability
    • Confirm that the WP-CLI Tool is installed and available by running the following command:
      wp --info
    • This command will display information about your WP-CLI installation if it is properly set up.
  4. Step 4: Update the Site URL and Home URL Options
    • To change the WordPress domain URL, you need to update the siteurl and home options in the WordPress database. Run the following command:
      wp option update siteurl 'https://new-domain.com'
      wp option update home 'https://new-domain.com'

      Replace 'https://new-domain.com' with your new domain URL.

  5. Step 5: Update Internal Links and Media URLs
    • After changing the site URL options, it’s essential to update the internal links and media URLs throughout your WordPress content. This ensures that all your pages and media files point to the new domain. Run the following commands:
      wp search-replace 'https://old-domain.com' 'https://new-domain.com' --skip-columns=guid
      wp search-replace 'http://old-domain.com' 'https://new-domain.com'