Managing WordPress from the Command Line

Managing your own server can be a lot of work. But it can also be one of the most rewarding experiences as you get to learn by trial and error. Did you know that you can manage WordPress in the command line?

WordPress development by itself does not mean you need to use the command line at all. For a long time I didn’t use anything in the command line. It wasn’t until I started working with Ruby on Rails that I was forced to get used to working in the command line. I know a few of great WordPress developers that lose their bearings when they start to get into the command line. So how can manage WordPress from the command line? Turns out there’s a tool called WP-CLI.

WP-CLI is an awesome tool that let’s you do all the common tasks of managing a WordPress site, like installing plugins, updating plugins, running backups, and even more! So let’s get started with WP-CLI.

Installing WP-CLI

You can install WP-CLI on any *nix based computer or server, so Macs and Linux. To get start you need to run the following command:

curl | bash

You’ll need to read the instructions as some environments might have some issues. I’ve had one machine in all my time using this where I’ve had to install extra stuff to get it working. One thing to watch out for is at the end of the installation process, you are going to have to put a few lines in your .bash_profile. It’s pretty simple though. It’s just copy/paste into that file.

Also, if you are using Bash and you want tab completions you can add the following:

# WP-CLI Bash completions
source $HOME/.wp-cli/vendor/wp-cli/wp-cli/utils/wp-completion.bash

You’ll then need to reload

source ~/.bash_profile

And if you ever want to update you’ll just need to use the following commands.

cd ~/.wp-cli
php composer.phar self-update
php composer.phar require 'wp-cli/wp-cli=@stable'

Using WP-CLI

After thinking about how to best use WP-CLI, I figured why not just show you in a screencast. So the rest of this post is available in the screencast. It runs about 20 minutes, but it’s definitely worth seeing how this cool tool works.

To learn more about plugins that are writing their own subcommands for WP-CLI, check out this wiki page on Github.