WordPress Local Development – Installing wpshell

This post was in draft status for a few months, but today I was trying to spin up wp-cli and had some configuaration issues. Instead of hacking around, I hopped onto wpshell instead. Since this draft post helped refresh my memory, I decided to finally post it.

I should also note that wpshell isn’t under active development, so in the long run wp-cli is probably the best option.

I first heard about wpshell when I read Danilo Ercoli’s interview on WPDaily. I was immediately interested because I’m working to update a plugin and the process of trying out different WordPress functions is a bit time-consuming.

What is wpshell? Simply put, wpshell allows you to run WordPress and PHP functions from the command line.

The installation is fairly easy. I’m running Mac OS X 10.8.3 and using MAMP for local development. Open Terminal and follow these steps:

First, move to your local WordPress directory. For me it’s: cd Applications/MAMP/htdocs/localdev

Check out wpshell by typing: svn co http://code.svn.wordpress.org/wpshell wpshell

Change to the wpshell subdirectory: cd wpshell

Edit wpshell: vi wpshell

After editing, my wpshell file looks like this:

shell=$(dirname $0)"/wpshell.php"
if [ -t 0 ]; then while [ true ]; do /Applications/MAMP/bin/php/php5.3.6/bin/php $shell if [ $? -eq 0 ]; then break; fi done else set -f read -s input echo $input | /Applications/MAMP/bin/php/php5.3.6/bin/php $shell stdin fi

Only the bolded lines need to be updated.

If you aren’t familiar with VIM commands, press a to edit the file. Enter CTRL + C when you’re done and then :wq to save the file. If you want to exit without saving enter :q! instead of :wq

Next, edit the wpshell-config.php file: vi wpshell-config.php

My config file looks like this:

$_SERVER['HTTP_HOST'] = 'Kevins-MacBook-Air.local';
$_SERVER['REQUEST_URI']     = '/';
$_SERVER['SERVER_ADDR']     = gethostbyname( $_SERVER['HTTP_HOST'] );
$_SERVER['HTTP_USER_AGENT'] = 'wpshell/1.0';
$_SERVER['REMOTE_ADDR']     = '';
$_SERVER['REMOTE_PORT']     = '0';

define('ADMIN_PLUGINS', true);

require dirname( __FILE__ ) . '/module-wpdb.php';
require dirname( __FILE__ ) . '/module-fshell.php';
require dirname( __FILE__ ) . '/module-hello.php';
require dirname( __FILE__ ) . '/module-wpreference.php';

require dirname( dirname( __FILE__ ) ) . '/wp-config.php';
chdir( dirname( dirname( __FILE__ ) ) );


Only the bolded lines need to be updated updated.

Once you’re done editing the file, enter CTRL + C and then enter :wq to save the file.

If all went well, you should be able to run wpshell. At the Terminal prompt enter: ./wpshell
and you should see the wpshell prompt. At this point you can enter php commands or WordPress functions.

Here are some resources if you’re having trouble installing wpshell

Thorsten’s blog post on wpshell

Daniel Bachhuber’s blog post and presentation slides

Daniel Bachhuber’s WordCamp presentation on wpshell and wp-cli

The video linked in the wpshell WATCHME file

One alternative is to use the Debug Bar Console plugin. Before I went through this whole process, I didn’t know about the Debug Bar Console, but now that I’ve installed it, I’ve found the functionality to be pretty similar.

Leave a Reply

Your email address will not be published. Required fields are marked *