WordPress wp-cli Kung-Fu Made Simple

WordPress wp-cli Kung-Fu Made Simple

Nuno has decided that he has created a project environment by hand one time too many, and explains how this process can be automated using a few wp-cli tricks.

With every new site or project, there comes a new WordPress install, and a few steps are needed before you can start to work. They usually involve one or more of the following:

  • download / update WordPress
  • create a new database and database user
  • set up Apache vhost
  • set up vhost url on system hosts file
  • install your favorite plugins
  • install a theme

This is a fairly simple process, which takes up a few minutes every time you start on a new project. However, since I like to automate things to decrease the chance of screwing up, and saving time, I’ve started to play around to see if I could somehow streamline this process.

While I’ve seen people come up with scripts to automate command-line stuff with WordPress, I haven’t seen anything near as complete, or as supported by the community as wp-cli. It was only natural to try using it for the task at hand.

I like to start work on a new website or theme by using Underscores, and thus wanted the script to install and activate the theme alongside the latest version of WordPress.  I spend most of the time just trying to get a downloadable file from their website automatically but eventually came to a solution using curl to get it.

After showing it around to friends I got the feedback that it would be handy to have it install a list of favorite plugins. Here is how the script ended up:

We start with the wp core download and wp core config commands; they will download the latest WordPress version and create a config file based on the supplied parameters at the command line interface. After that, we issue the wp core install command, which starts the installation (much like if you were visiting the page on a regular browser). Next, we add the vhost to Apache and restart it. After that, the vhost gets added to the system’s host file, and finally we download and install our starter theme.

If you don’t immediately grasp how wp-cli it works, you might well be tempted to skip it. However if you stick with it for a while and learn how to leverage it, you will find that it can save you a good few hours of work. This is just an example of how wp-cli can be useful.


  1. dan a says

    Not sure if you are familiar with Serverpress’s Desktopserver app. It allows you to build local wordpress sites. You can store a zip version of a “blueprint” site that loads exactly how you want it to and directly deploy it to a live site as well. Just something to consider.

  2. says

    You can further shorten this really cool script by activating the plugins and themes, immediately after installation using the –activate flag

    Example: wp theme install –activate


Leave a Reply