Getting Started with WP-CLI on AMIMOTO

We will introduce to you a useful command-line tool, “WP-CLI”.

WP-CLI


http://wp-cli.org/

WP-CLI is a command line tool that can do almost everything about WordPress.

For example,

  • Installation or upgrade of WordPress core
  • Install updates for plugins and themes, enable and disable
  • Managing Databases
  • Operating posts and pages

WP-CLI is installed in AMIMOTO AMI ver1.1 or later. 

Operation example using WP-CLI

First of all, please cd to the directory where WordPress is installed, then run the wp command.

  • When you use Amimoto AMI and logged in as ec2-user, you can’t create directories and files, so run with sudo.

Check the info of the installed plugins with:

$ wp plugin status

Enable and disable plugin(s) (can be specified more than one)

Enable and disable Akismet and WP Multibyte Patch.

$ wp plugin activate wp-multibyte-patch akismet
$ wp plugin deactivate wp-multibyte-patch akismet

wp-cli-plugin

Install and enable (example: Breadcrumb NavXT)

$ wp plugin install breadcrumb-navxt --activate

※ It is also possible to install by specifying the .zip file of a plugin other than the official directory.

wp-cli-plugin2

Plugin updates

$ wp plugin update akismet

Import and export of database

$ wp db export foo.sql
$ wp db import foo.sql

wp-cli-db

※ phpMyAdmin is available in Amimoto managed hosting plan.
Using phpMyAdmin is possible by rewriting the conf file if you have created an instance from Amimoto AMI by yourself.

Search and replace text in the database

$ wp search-replace 'http: //example.dev' 'http://example.com'

※ string that has been serialized are also processed correctly.

 

The command line

You can perform almost all the same actions from the dashboard as commands introduced here. The advantage of doing with commands is that you can automate those actions. For example, if you want to install some plugins you always use, you may search, install and activate those plugins from dashboard for each time, however, with using WP-CLI, once you write a shell script to do those actions, you just run the script for the new installation of WordPress.


The commands introduced here are just some examples.
There are still a lot of commands, so please refer to the official documentation.