Installing wp-cli on macOS – WordPress has a command line tool which operates similar to what Drush does for Drupal, it is called wp-cli and runs on macOS/Linux operating systems with a minimum of PHP 5.3.2 or later and WordPress 3.5.2 or later.
Install wp-cli on macOS
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
neilg@[~]: php wp-cli.phar --info PHP binary: /usr/bin/php PHP version: 5.6.30 php.ini used: WP-CLI root dir: phar://wp-cli.phar WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /Users/neilg WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 1.4.1
Make it executable
chmod +x wp-cli.phar
Move it into your Path
mv wp-cli.phar /usr/local/bin/wp
In the above command as well as moving the file name is also changed to just wp
Test it by running
Output should be similar to
PHP binary:/usr/local/php5-5.5.5-20131020-222726/bin/php neilg@[~]: wp --info PHP binary: /usr/bin/php PHP version: 5.6.30 php.ini used: WP-CLI root dir: phar://wp-cli.phar WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /Users/neilg WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 1.4.1
Now all you have to do is operate the wp-cli commands by changing into your WordPress webroot site folders, for example to get a list of plugins for a WordPress site ‘cd’ into the webroot directory and run:
wp plugin list
Once all is working explore the available commands by running ‘wp’ to see the list of the commands and then more specifically by running wp help and the command name such as:
wp help plugin
Using the wp-cli Completion Script
It is also a good idea to use the wp-cli bash completion script so you can tab complete commands.
Download the wp-completion.bash file and move it into your home folder and reference it in your .bash_profile by adding in the bash_profile…
Now just type wp and tab to see available commands!
wp-cli comes bundled with development tools like VVV Vagrant and Valet. In VVV instance you need to SSH in to the vm and run it – by installing it also on macOS you can run it natively in the WP webroot folder without SSH’ing in.