WordPress command line interface (WP-CLI) guide

WP-CLI is a tool for managing your WordPress website via the command line. This may come in handy if you want to manage your WP instance without going through the web interface, or automate certain operations (change of Settings, perform backup etc.)

For example, here is a sequence of commands for installing a fresh copy of wordpress:

Installing WP-CLI as a command

Using MAMP on OSX

You may find trouble connecting to the Database using wp-cli if you’re using MAMP. It is because the MySQL socket file is not located at the default location.

Method 1: symoblic link /tmp/mysql.sock to MAMP

I think this solution is quite neat, it should work most of this time, since PHP look for /tmp/mysql.sock by default

Method 2: Update php.ini

Find the php.ini by typing “php –ini” in the Terminal

Edit the php.ini, change the default_socket

Dependency on the “mysql” command

Some sub-command in the wp-cli (e.g. wp core install) requires the “mysql” command line tool,  you should have it installed

Usage Example: Automate configuration of a fresh WordPress installation

There are a bunch of configs that must be changed after a fresh-install, you can save the commands as a bash file to automate your workflow


Share your thoughts