Knowledgebase Home / How to Install and Manage WordPress Sites With WP-CLI

How to Install and Manage WordPress Sites With WP-CLI


How to Install and Manage WordPress Sites With WP-CLI

This tutorial will help you to install and manage WordPress with the WP-CLI. WP-CLI provides a command line interface for WordPress. WP-CLI provides users the tools necessary to install and update plugins, create databases without using a web browser.

PREREQUISITES

  • Unix-like environment (Linux, FreeBSD, Cygwin).
  • PHP 5.4 or later
  • WordPress 3.7 or later

INSTALLATION

Connect to your Server’s console through SSH. You can now download the file wp-cli.phar using wget or curl.

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

Next, check whether the downloaded Phar file is working.

php wp-cli.phar --info

Now, set the permission to make the Phar file executable with the following command:

chmod +x wp-cli.phar

Move the file wp-cli.phar to a new directory named wp under /usr/local/bin. This allows us to execute the WP-CLI commands by typing ‘wp’ at the start.

sudo mv wp-cli.phar /usr/local/bin/wp

Run wp –info to check whether the installation was successful.  If the installation was successful, you’ll see the following output below,

Verifying the installation using wp --info.

Verifying the installation using wp –info.

MANAGING WORDPRESS WITH WP-CLI

Lets go over some basic and useful WP-CLI commands.

WP-CLI HELP SYSTEM

WP-CLI comes with a guide which can be accessed by using “wp help“. You can get a detailed info about a specific command here. For example, if you want to know more about config command, you can type in:

wp help config

A sample output:

Man page of wp config.

Man page of wp config.

MANAGING THEMES

To list themes present in your WordPress, you can use the following command:

wp theme list

The output will be:

Managing WordPress themes.

Managing WordPress themes.

If you want a different theme, use the following command:

wp theme activate twentyseventeen

MANAGING PLUGINS

Like themes, plugins can also be installed and managed using wp-cli.

The following command is used for listing the plugins that were already installed on your WP site. 

wp plugins list

Also you can search and install the plugins available from the command line. For example,  use the command below to search for the plugin “Yoast SEO”.

wp plugin search yoast

The output will be:

Managing WordPress plugins via the command line.

Managing WordPress plugins via the command line.

For installing and activating the plugin, you can use the below command.

wp plugin install wordpress-seo --activate

UPDATING WORDPRESS

When updating WordPress from the command line, you need to update the core WordPress files and the database to complete the update process.

 Update the WordPress core files with the command shown below:

wp core update

Then, update the database using the command below:

wp core update-db

The commands we discussed on this guide are just the tip of the iceberg. There are many more commands to manage your database, posts, and multi-sites. Refer to this documentation from WordPress for more information on WP-CLI commands.

Conclusion

Hooray! Now you know how to manage your WP installation from the command line. For more information on WP-CLI, please visit their official page here.

We'd love to hear your thoughts. How can we make this better?


If the steps above listed in this article do not resolve your issue, please feel free to open a support ticket and we’d be happy to take a look.

Looking for better web hosting? Sign up today and take 50% off your first month with promo code: 1stmonth50

Our Guiding Principles

  • Provide consistent, stable and reliable web hosting services.
  • Ensure rapid ticket response and quick resolutions to issues.
  • Never saturate or over-provision servers to ensure stability and speed for our customers.
  • Use only high quality enterprise-class hardware to ensure minimal downtime from hardware failures.
  • Provide clear pricing with no hidden fees or gotchas.