Hosting

  1. Home
  2. Support
  3. Hosting
  4. WordPress
  5. WP-CLI

WP-CLI

WP-CLI, (WordPress Command Line Interface), is a powerful way to manage your WordPress site without ever touching either the WordPress admin dashboard or the hosting control panel. If you’re comfortable with the command line, WP-CLI offers a faster, more efficient way to perform many common tasks. This article will guide you through some of the basics of getting started with WP-CLI that is pre installed on our hosting packages.

This guide assumes you already have WordPress installed and are familiar with using SSH.

Granting SSH Access

In this example we are going to be using SSH with password authentication. I’d recommend using the PuTTY SSL client for Windows.

  1. Login to your hosting control panel.
  2. Click on the website you wish to SSH into.
  3. Click AdvancedDeveloper tools, click SSH password authentication.
  4. Click Reset next to Password to set your new SSH password. I’d recommend using the built in secure password generator by clicking the key icon. Make a note of this password.
  5. Below Login command you will see the details you need to use. Depending on the client you are using to connect, you could just copy and paste this in, then enter your password, but I will break down the details of the login command.
    Example command:

    ssh -p 22 youruser@89.248.52.130

    SSH = The protocol you are using
    -p 22 = The Port you want to connect to
    youruser = Your username
    89.248.52.130 = The host you are connecting to

  6. Once you have logged in you will need to navigate to your WordPress directory, by default WordPress will be installed in the public_html directory, to get there we would type,
    cd public_html
  7. Now we can can make use of WP-CLI.

Basic Commands

To confirm you are in the right location and WP-CLI is working as expected we can simply type wp or wp help. This will display a list of available commands and their basic usage.

Updating WordPress

Keep your WordPress core up-to-date with wp core update. This command downloads and installs the latest stable version.

Plugin Management

Use wp plugin list to see all installed plugins, wp plugin install <plugin-name> to install a new one, wp plugin activate <plugin-name> to activate it, and wp plugin deactivate <plugin-name> to deactivate it. Updating plugins is done with wp plugin update <plugin-name>.

Database tools

Wp-CLI is fantastic for database backups and imports.

Use wp db export to create a compressed SQL file dump of your database. This database file can be imported later if needed with wp db import backup.sql.

Search and replace

Replace ‘OldSiteName‘ with ‘NewSiteName‘ within all page content:

Test run:

wp search-replace ‘OldSiteName’ ‘NewSiteName’ wp_posts –include-columns=post_content –dry-run

Live run:

wp search-replace ‘OldSiteName’ ‘NewSiteName’ wp_posts –include-columns=post_content


 

These are just a few basic examples. WP-CLI offers a vast array of commands for almost any WordPress management task. For a full list of commands and detailed documentation, refer to the official WP-CLI handbook https://make.wordpress.org/cli/handbook

Was this article helpful to you? Yes No
Click here for full details