This is a step by step tutorial on how I was able to get WP-CLI up and running on Mavericks with AMPPS. The biggest issue that you will typically face when installing WP-CLI along side a web host software stack (MAMP, XAMPP, AMPPS) on a Mac is that WP-CLI will want to use the PHP binary that is bundled with the OS. When this happens, WP-CLI cannot communicate with the local MySQL instance and will usually return a bit of HTML in the terminal that says something along the lines of “Error Establishing A Database Connection” and/or “Can’t connect to local MySQL.”
Step 1 – Install WP-CLI
curl -L https://github.com/wp-cli/wp-cli/releases/download/v0.13.0/wp-cli.phar > wp-cli.phar
And then running these commands in order to be able to call WP-CLI by just using ‘wp’:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/bin/wp
Step 2 – Configure WP-CLI to use AMPPS binaries
At this point, if you’re using AMPPS to serve web sites locally, you’ll notice that any call to ‘wp’ within a site directory will return the “Error Establishing A Database Connection” message. This is due to WP-CLI using the bundled PHP binary which is separate from the binary you are using for AMPPS. The way to fix this is by adding some values to your bash_profile file. To open the .bash_profile file, run this command:
open ~/.bash_profile
This should launch TextEdit window for editing your .bash_profile file. Add this line (modify the path to AMPPS to match your directory configuration) and save the file:
export PATH="/Applications/AMPPS/php/bin:/Applications/AMPPS/mysql/bin:$PATH"
Now you will need to restart Terminal in order for the updates to be applied. Verify the new path has been set by using this command:
wp --info
The PHP binary setting should now be pointing to the PHP binary within your AMPPS directory. If not, go back and verify that the paths you entered in the .bash_profile file are correct.