How to install and use wp-cli for Wordpress administration

We all know that WordPress is the most used Open source application these days and there are quite a lot of useful tools released for improving the client experience with that application.

The Best way to manage your Wordpress is with WP-CLI, this article will cover how to install and how to manage your Wordpress using wp-cli tool.

     WP-CLI is a set of command-line tools for managing WordPress installations. You can update plugins, configure multi-site installs and much more, without using a web browser. WP-CLI provides a command-line interface for any action you might want to perform in the WordPress admin.

       The Command Line Interface and it is used to execute shell commands towards the operating system of a computer. No matter if you would like to send the commands to your local computer or the web server hosting your website you will have to use a Command Line Interface in order to interact with different services.

Login into your Wordpress host and download the wp-cli

[root@aodba tmp]# wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
--2016-10-19 10:53:29--  https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4967063 (4.7M) [application/octet-stream]
Saving to: wp-cli.phar

100%[=========================================================================================================================================================] 4,967,063   29.4MB/s   in 0.2s

2016-10-19 10:53:31 (29.4 MB/s) - wp-cli.phar saved [4967063/4967063]

Verify the wp-cli package info

[root@aodba tmp]# php wp-cli.phar --info

PHP binary:     php
PHP version:    5.3.29
php.ini used:   /etc/php.ini
WP-CLI root dir:        phar://wp-cli.phar
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.24.1

Change the permission of the wp-cli.phar file and put it in the /usr/local/bin/wp folder, this is make it available from any point in your sistem

[root@aodba tmp]# chmod +x wp-cli.phar
[root@aodba tmp]# sudo mv wp-cli.phar /usr/local/bin/wp 
[root@aodba tmp]# php wp-cli.phar --info 

PHP binary: php 
PHP version: 5.3.29 php.ini 
used: /etc/php.ini 
WP-CLI root dir: phar://wp-cli.phar WP-CLI packages 
dir: WP-CLI global 
config: WP-CLI project 
config: WP-CLI version: 0.24.1

Configure your wp-cli with your Wordpress installation

  • if you try to run it without the configuration setup you will get an error
[root@aodba]# wp plugin list
Error: This does not seem to be a WordPress install.
Pass --path=path/to/wordpress or run wp core download.
Note:  seems like you need to install wordpress core.

Install wordpress core using the wp-cli tools

wp core install --url="your_domain_name"  --title="Your Blog Title" --admin_user="admin" --admin_password="your_password" --admin_email="your_email"

Conclusion:

We have installed wp-cli and therefore we are ready to learn how to manage our Wordpress instance with it. Check the next article on how to use WP-CLI with full examples and details a