Coding Agency for Web Development » Freestyle » WordPress and SSH: Introduction to WP-CLI

WordPress and SSH: Introduction to WP-CLI

READING TIME: MIN

Like we mentioned in Part 1 of this “SSH and WordPress” series, WP-CLI is something that lets you skip the login and navigation and execute text commands for WordPress via a terminal environment. Use WP-CLI, and anything from backups to updates for plugins and queries can all happen in no time.

What you need for WP-CLI

Some web hosts have WP-CLI by default, in which case, skip right ahead to the next section after ‘WP-CLI Installation’. For setting WP-CLI up yourself, you’ll need to meet a few requirements. Besides the SSH access we set up in part 1, you’ll need PHP (at least 5.3.2), WordPress 3.4 or newer, and a terminal environment of the sort we’ve already set up.

WP-CLI Installation

Start by logging in to your server over SSH. You can then use the cURL command or wget command to download WP-CLI. The up-to-date setup (as a .phar file) can be found on the GitHub page for WP-CLI. So you can type:

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

WP-CLI will now be installed to the root directory.

For the next part, we need to set permissions so we can execute WP-CLI, for which we enter:

chmod +x wp-cli.phar

In addition, you may also move the downloaded .phar file to a folder and name it just ‘wp’. This way, prefixing ‘wp’ will make any WP-CLI command work. Type:

  Using SFTP for file management on WordPress

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

Now we’re good to go.

Basic WP-CLI Commands

We can now execute the commands. The most basic command ‘wp help’ is something you can use to access the full WP-CLI help database to learn what each command does, and even what role the subcommands play.

In order to execute the help command, you need to move to the directory that you installed WP-CLI to. To do this you may use ‘ls’ and reveal the current directory status. WP-CLI also allows you to install themes using the following:

wp theme install name_of_theme

Then we can activate the theme by:

wp theme activate name_of_theme

The themes are directly imported from the Theme Repository.

Commands can be used to install plugins as well from the official repository with the following command:

wp plugin install name_of_plugin

And activation will be:

wp plugin activate name_of_plugin

To disable the plugins, on the other hand, it’s as simple as typing

wp plugin deactivate name_of_plugin

You can type

wp plugin list

to show all the available plugins. To update all your eligible plugins you can execute

wp plugin update

If you want to get some more fine-grained control, type

wp plugin update –-all --dry-run

to give you the list of plugins that would be updated by the first command.

  How to Add the Tony Stark Factor to Your WordPress Website

In fact, even WordPress itself can be installed if you type and execute

wp core install

Of course, you need to complete the command with other attributes like URL, username, password and email.

To learn more about the WP-CLI commands, you can refer to the official WP-CLI manual at their website.

You are now ready to deploy all the advanced and power-user tools and control your WordPress website and environment better. Some hosting solutions will even let you use Git, npm and other tools. As you use SSH and learn more about WP-CLI, you’ll learn more and more things you can achieve with SSH and the command line, and in no time, you’ll be a natural at doing things the smarter way!

With the power of SSH in your hands, your WordPress experience is faster, and you can say goodbye to the days of clicking through page after page to perform basic WordPress functions. As promised in part 1, you are now indeed a WordPress ninja with SSH!

Tags:

Vipe Team

Author Vipe Team

Our tireless team who creates high-quality WordPress-related content for you 24/7/365.