WP-CLI common commands

WP-CLI is a set of command-line tools for managing WordPress installations. You can update plugins, set up multisite installs and much more, without using a web browser.

Requirement of WP-CLI utility

PHP 5.4 or later
WordPress 3.7 or later
  • Download WP-CLI utilty through wget or curl

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

  • Check if it works

php wp-cli.phar –info –allow-root

To be able to type just wp, instead of php wp-cli.phar, you need to make the file executable and move it to somewhere in your PATH. For example

chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp

[[email protected]_1 wordpress]# wp --allow-root theme status
3 installed themes: A twentyfourteen 1.1 I twentythirteen 1.2 I twentytwelve 1.4 Legend: A = Active, I = Inactive
  • Installation of plugin hello-dolly through WP-CLI
[[email protected]_1 httpdocs]# wp --allow-root plugin install hello-dolly
Installing Hello Dolly (1.6) Downloading install package from https://downloads.wordpress.org/plugin/hello-dolly.1.6.zip... Unpacking the package... Installing the plugin... Plugin installed successfully.
  • Check WP core version
[[email protected]_1 httpdocs]# wp --allow-root core version
  • Check plugin status
[[email protected]_1 httpdocs]# wp --allow-root plugin status
3 installed plugins: I akismet 3.0.1 I hello-dolly 1.6 I hello 1.6 Legend: I = Inactive

NOTE: If you have update version of plugin it will show like this

Legend: I = Inactive, A = Active, U = Update Available
  • Updating WordPress, Updating WordPress is simple with WP-CLI. To do this, type the following command:
wp core update
  • Whenever you update WordPress, you should also update the database. To do this, type the following command
wp core update-db
  • Backing up and restoring a WordPress database

It is a good idea to periodically back up your WordPress database. By combining WP-CLI’s backup functionality with a cron job, you can automatically back up your database on a set schedule.

To back up a WordPress database using WP-CLI, type the following command:

wp db export
Success: Exported to test1.sql

When this command finishes, you have a .sql file that you can store in a safe location. If you need to import a database into WordPress at some point, type the following command. Replace filename with the name of the database backup file:

wp db import test1.sql
Success: Imported from test1.sql
  • Update themes
[[email protected]_1 httpdocs]# wp --allow-root theme update webby-blue-10
  • Delete Themes
[[email protected]_1 httpdocs]$ wp --allow-root theme delete webby-blue-10
Success: Deleted 'webby-blue-10' theme.
  • Update WP plugins
[[email protected]_1 httpdocs]# wp --allow-root plugin update akismet
Success: Successfully executed the cron event 'wp_update_plugins'
  • Delete WP Plugin
[[email protected]_1 httpdocs]# wp --allow-root plugin deactivate akismet && wp --allow-root plugin delete akismet

Leave a Reply

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