How to manage WordPress from the command line with the cPanel WordPress Toolkit

This article describes how to use the wp-toolkit program to manage WordPress sites from the command line, as well as how to use it in cron jobs to automate tasks.

The wp-toolkit program is part of the cPanel WordPress Toolkit. However, it is currently only available for accounts with root access.

About wp-toolkit

It is often quicker and easier to do many tasks at the command line, and WordPress administration is no exception. You can use the wp-toolkit program to back up and restore WordPress sites, install plugins and themes, reset the administrator password, and more. Additionally, you can run wp-toolkit in cron jobs to automate tasks.

Because wp-toolkit is a command-line tool, it helps if you already have some basic familiarity with the Linux command-line environment. If you have never worked in the Linux command-line environment before, you can learn the basics by reading this article.

Using wp-toolkit at the command line

wp-toolkit has many commands, and the rest of this article is only an introduction to its capabilities. However, to view the wp-toolkit online help at any time, type the following command:

wp-toolkit --help

Alternatively, to view the online help for a specific wp-toolkit subcommand, add the -command option. For example, to view the online help for the wp-toolkit—list command, type the following command:

wp-toolkit --help -command list
You must run wp-toolkit as the root user.
Listing WordPress installations

To view a listing of the WordPress sites managed by WordPress Toolkit on your account, type the following command:

wp-toolkit --list

A listing appears that resembles the following output:

  ID   Installation Path  Owner ID         State  Hidden                 Website URL                    Name  Version
   1     /public_html/wp         2  Outdated PHP   false      https://example.com/wp              My Website    5.8.1
   2    /public_html/wp2         2  Outdated PHP   false     https://example.com/wp2        My Other Website    5.8.1
The ID column shows the instance ID for the WordPress installation. Make a note of these ID numbers, because you need them to run many of the commands in wp-toolkit.
Displaying WordPress installation information

To list information about a WordPress installation managed by WordPress Toolkit, type the following command. Replace X with the instance ID of the installation that you want to check:

wp-toolkit --info -instance-id X

This command displays information about the site, such as:

  • Installation path.
  • Website URL.
  • WordPress version installed.
  • Administrator's e-mail address.
  • Automatic update policy.
  • Security status.
  • SSL/TLS configuration.
  • List of all of the plugins and themes installed.
Using sets to manage plugins and themes

wp-toolkit uses the concept of a set to manage plugins and themes. A set is a custom collection of themes and plugins that you can install on your sites. For example, you could create a “Basic” set that contains plugins and themes you want available on all of your sites, and an “Extras” set that contains additional plugins you may not want to install on every site.

Let's create a simple set that contains one plugin and one theme. The first step is to upload the plugin and theme to the wp-toolkit cache. To upload a plugin, you need the URL to the plugin's zip file. You can obtain this from the wordpress.org site. The following command demonstrates how to upload the “Hello Dolly” plugin to the cache:

wp-toolkit --plugins -operation add -source-url https://downloads.wordpress.org/plugin/hello-dolly.1.7.2.zip

Next, we upload a theme. To upload a theme, you need the URL to the theme's zip file, which you can obtain from the wordpress.org site. The following command demonstrates how to upload the “Twenty Twenty” theme to the cache:

wp-toolkit --themes -operation add -source-url https://downloads.wordpress.org/theme/twentytwenty.1.8.zip

Now we are ready to create a set. Let's call the set “Basic”. To create this set, we run the following command:

wp-toolkit --sets -operation add -name Basic

After we create the set, wp-toolkit shows the set's ID number, which we need for subsequent commands. In this case, the set ID is 7:

  ID     Name                            Owner GUID
   7    Basic  9475252e-1234-4321-4444-4923d4521ae7

We are ready to add the plugin and theme to the set. To do this, we need the set ID, the plugin's slug, and the theme's slug. The slug is usually the basename of the zip file. For example, the slug of hello-dolly.1.7.2.zip is hello-dolly, and the slug of twentytwenty.1.8.zip is twentytwenty.

Here is the command to add the plugin to the set:

wp-toolkit --sets -operation add-plugin -set-id 7 -plugin-slug hello-dolly

The command to add the theme to the set is similar:

wp-toolkit --sets -operation add-theme -set-id 7 -theme-slug twentytwenty

We now have a “Basic” set that contains the “Hello Dolly” plugin and “Twenty Twenty” theme. To confirm this, run the following command:

wp-toolkit --sets -operation info -set-id 7

wp-toolkit lists the plugins and themes that belong to the set.

To install this set on a WordPress installation, we run the following command, replacing X with the instance ID of the installation on which we want to install the set:

wp-toolkit --sets -operation install -set-id 7 -instance-id X

This is a simple example to give you an idea of how sets work. Typically, a set contains multiple plugins and themes to make site configuration easier.

Configuring Smart Updates

With wp-toolkit, you can easily configure Smart Updates for your WordPress sites.

The Smart Updates feature enables you to test an update without actually affecting the site. It does this by creating a full clone of the website, running a number of preliminary checks, updating the cloned website, and running the checks again to see if the update breaks anything. The results include before-and-after screenshots that you can compare to make an informed decision about whether or not to proceed with the update on your “live” site.

To check the Smart Updates status of a WordPress installation, type the following command. Replace X with the instance ID of the installation to check:

wp-toolkit --smart-update -operation status -instance-id X

To enable Smart Updates, type the following command. Replace X with the instance ID of the installation:

wp-toolkit --smart-update -operation enable -instance-id X

To disable Smart Updates, type the following command. Replace X with the instance ID of the installation:

wp-toolkit --smart-update -operation disable -instance-id X
Backing up and restoring WordPress content

You can quickly and easily back up and restore site content using wp-toolkit. All files and the database (which includes posts, pages, comments, and categories ) are exported to a compressed .tar.gz file. This backup file is located in the /home/username/wordpress-backups directory, where username represents your account username.

To back up a WordPress installation, type the following command. Replace X with the instance ID of the installation to back up:

wp-toolkit --backup -operation backup -instance-id X

When this command finishes, you can transfer the .tar.gz file to a safe location.

To restore a backup, type the following command. Replace X with the instance ID of the installation, and replace filename with the name of the backup file to restore (do not include the full path, specify only the filename):

wp-toolkit --backup -operation restore -instance-id X -filename filename

To obtain a list of backup files available for restoration, type the following command. Replace X with the instance ID of the installation:

wp-toolkit --backup -operation list -instance-id X
Resetting the administrator password

You can use wp-toolkit to reset the WordPress administrator password. To do this, type the following command. Replace username with the login name of the administrator, and replace X with the instance ID of the installation:

wp-toolkit --site-admin-reset-password -admin-login username -instance-id X

After you run this command, wp-toolkit displays the new, randomly generated password for the specified administrator.

If there is only one administrator for the specified site, you can omit the -admin-login option.

Using wp-toolkit in a cron job

By combining wp-toolkit's functionality with cron jobs, you can automatically do administrative tasks that are time consuming and repetitive from the  graphical administration interface.

For example, the following cron line demonstrates how to back up a WordPress site automatically every day at 2:15 AM by using wp-toolkit:

15 2 * * * /usr/local/bin/wp-toolkit --backup -operation backup -instance-id id >/dev/null 2>&1

More Information

For more information about the wp-toolkit program, please visit https://docs.cpanel.net/knowledge-base/cpanel-developed-plugins/wordpress-toolkit-command-line-interface.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.