Get a free advice now!

    Pick the topic

    Developer OutsourcingWeb developingApp developingDigital MarketingeCommerce systemseEntertainment systems

    Thank you for your message. It has been sent.


    Migrate WP using SSH and WP CLI

    Migrate WP using SSH and WP CLI

    CHALLENGE: we would like to migrate a WordPress website from old hosting to new

    SOLUTION: use the SSH connection and the WP CLI command line

    Migrating a website can be a difficult and time-consuming process. When moving to new hosting, we want to make sure that all files and the database are properly copied. Copying files using an FTP Client can be slow and inefficient. The good news is that nowadays most hostings have SSH access, which allows us to migrate an entire website really fast. It is really helpful when a website has a lot of uploads and a big database, migrating gigabytes of data isn’t a problem anymore.

    STEP 1 – zip files and database

    We’re going to export a WordPress database to .sql dump and then pack everything into a tar package (including hidden files).

    # export database
    wp db export
    # zip everything
    tar -zcvf ../my-website-all-1.tar.gz .

    STEP 2 – copy files to new hosting

    Now we have the entire website packed into one file:  my-website-all-1.tar.gz. We can copy it to new hosting using the WinSCP application or any other SCP/SSH/FTP/SFTP Client. A different way would be to use a new hosting SSH and the wget command:

    # get file from external url
    # get file from external url with htpasswd protection
    wget –user=user123 –password=mypass321

    STEP 3 – unpack files, import database

    We already have all files on the new hosting. Now we’re going to: unpack everything, put new database credentials into wp-config.php, and import .sql database dump.

    # unpack files
    tar -zxvf  my-website-all-1.tar.gz
    # add new database name, new db_user and db_password into wp-config.php file
    nano wp-config.php
    # import database
    wp db import wp-db-yourfile321.sql
    # clean up temporary files
    rm my-website-all-1.tar.gz
    rm import wp-db-yourfile321.sql

    STEP 4 – DNS configuration

    At this point, migration should be completed. All files and the database have been moved to a new hosting account. The last step will be to change DNS configuration. We want to make sure that our domain points to the new hosting.

    • DNS configuration: change DNS A Record for domain to point to the new hosting IP

    STEP 5 (optional) – change domain url

    Sometimes when migrating a website we would like to change site url. It can be a totally new domain name or just the preparation of a test page / staging website with a temporary url. The WP CLI search-replace command allows us to replace domain urls in a database.

    # Standard wordpress – replacing DB urls
    wp search-replace '' '' –all-tables –allow-root
    # Multisite WordPress – replace database urls
    # First step - change wp-config.php - DOMAIN_CURRENT_SITE to:
    wp search-replace 'wp_*options' wp_blogs
    wp search-replace '' '' --all-tables –network
    wp search-replace '' '' --all-tables –network
    wp search-replace "http:\/\/" "https:\/\/" --all-tables --network


    Styles are not displayed properly / some elements look incorrect / broken

    Clear cache plugin cache / rebuild cache of assets (css/js)

    Browser padlock displays the following error: Your connection to this site is not fully secure / Connection is Not Secure / Page was loaded over HTTPS, but requested an insecure image.

    Make sure all database urls have been replaced  from the http:// to https:// domain protocol.

    Before changing DNS records, I would like to see how the page works on the new hosting.

    You can do it by hardcoding the IP address in your Windows hosts file: \System32\drivers\etc\hosts , example row:


    Alternative solution – WordPress plugins

    A different way to migrate a WordPress site is to use WordPress backup plugins. The most popular and reliable solutions are: UpdraftPlus and All-in-One WP Migration. Keep in mind that the free versions of those plugins have limited functionality and migrating a lot of gigabytes can be time consuming.

    This concludes today’s tutorial. Make sure you follow our blog for other useful suggestions.

    0 response

    Add comment

    Your email address will not be published. Required fields are marked *

    Popular news

    Streamlining Business Growth: Leveraging Discovery for SME Success
    • Services
    • Trends

    Streamlining Business Growth: Leveraging Discovery for SME Success

    September 11, 2023 by createIT
    Benefits of using WordPress
    • Technology
    • Trends

    Benefits of using WordPress

    June 30, 2023 by createIT
    Find out which project flow will suit your idea
    • Services
    • Trends

    Find out which project flow will suit your idea

    June 9, 2023 by createIT
    How to become a Frontend Developer? Essential tips
    • Technology
    • Trends

    How to become a Frontend Developer? Essential tips

    June 6, 2023 by createIT
    Host React App with Netlify
    • Dev Tips and Tricks
    • Technology

    Host React App with Netlify

    May 31, 2023 by createIT

    Support – Tips and Tricks
    All tips in one place, and the database keeps growing. Stay up to date and optimize your work!

    Contact us