Tag Archives: Update WordPress

How to Install and Manage WordPress Sites With WP-CLI

The following steps are meant to be run with root privileges on a server (VPS hosting). This feature comes preinstalled with our shared/reseller hosting accounts.

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

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