How to install wp-cli on your server

WP-CLI is a command-line interface for WordPress.  Through it, you can manage your installations from the command line.

Official requirements you should check prior to installing WP-CLI:

– UNIX-like environment (OS X, Linux, FreeBSD, Cygwin); limited support in Windows environment
– PHP 5.4 or later
– WordPress 3.7 or later. Versions older than the latest WordPress release may have degraded functionality

The first thing we must do is to download the wp-cli phar file. As root, use the command:

# curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
root@web [/]# curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
 100 5294k 100 5294k 0 0 8635k 0 --:--:-- --:--:-- --:--:-- 8637k
 root@web [/]#

Now, let’s check the phar file is in good condition and to get some info about the wp-cli. Use:

# php wp-cli.phar --info
root@web [/]# php wp-cli.phar --info
 OS: Linux 2.6.32-042stab134.3 #1 SMP Sun Oct 14 12:26:01 MSK 2018 x86_64
 Shell: /bin/bash
 PHP binary: /opt/cpanel/ea-php73/root/usr/bin/php
 PHP version: 7.3.4
 php.ini used: /opt/cpanel/ea-php73/root/etc/php.ini
 WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
 WP-CLI vendor dir: phar://wp-cli.phar/vendor
 WP_CLI phar path: /
 WP-CLI packages dir:
 WP-CLI global config:
 WP-CLI project config:
 WP-CLI version: 2.1.0
 root@web [/]#

We want to use the wp-cli tool with the “wp” command so let’s run the commands:

# chmod +x wp-cli.phar
# mv wp-cli.phar /usr/local/bin/wp

The first command makes the wp file executable, the second one moves it to the /usr/local/bin/ folder.

Everything is done now, let’s test it. Use:

# wp --info
root@web [/]# wp --info
 OS: Linux 2.6.32-042stab134.3 #1 SMP Sun Oct 14 12:26:01 MSK 2018 x86_64
 Shell: /bin/bash
 PHP binary: /opt/cpanel/ea-php73/root/usr/bin/php
 PHP version: 7.3.4
 php.ini used: /opt/cpanel/ea-php73/root/etc/php.ini
 WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
 WP-CLI vendor dir: phar://wp-cli.phar/vendor
 WP_CLI phar path: /
 WP-CLI packages dir:
 WP-CLI global config:
 WP-CLI project config:
 WP-CLI version: 2.1.0
 root@web [/]#

If you are running cPanel on the server, the wp-cli tool is already installed in /usr/local/cpanel/3rdparty/bin/wp. Many times, 3rd party apps are not updated frequently, so you may want to install wp-cli manually, as described above.

To update the wp-cli tool, use:

# wp cli update
root@web [/]# wp cli update
Success: WP-CLI is at the latest version.
root@web [/]#

You can also install wp-cli through yum:

# yum install wp-cli
root@web [~]# yum install wp-cli
Loaded plugins: fastestmirror, tsflags, universal-hooks
Loading mirror speeds from cached hostfile
 * EA4: 185.125.185.32
 * cpanel-addons-production-feed: 185.125.185.32
 * cpanel-plugins: 185.125.185.32
 * base: mirrors.advancedhosters.com
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: mirror.teklinks.com
 * updates: mirror.cogentco.com
Resolving Dependencies
--> Running transaction check
---> Package wp-cli.noarch 0:2.4.0-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                Arch                                   Version                                       Repository                            Size
========================================================================================================================================================================
Installing:
 wp-cli                                 noarch                                 2.4.0-2.el7                                   epel                                 1.0 M

Transaction Summary
========================================================================================================================================================================
Install  1 Package

Total download size: 1.0 M
Installed size: 5.3 M
Is this ok [y/d/N]: y
Downloading packages:
wp-cli-2.4.0-2.el7.noarch.rpm                                                                                                                    | 1.0 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wp-cli-2.4.0-2.el7.noarch                                                                                                                            1/1
  Verifying  : wp-cli-2.4.0-2.el7.noarch                                                                                                                            1/1

Installed:
  wp-cli.noarch 0:2.4.0-2.el7

Complete!
root@web [~]#
wp cli logo
wp cli Logo

Thank you.

Related articles:
Most used wp-cli commands

Resources:
https://wp-cli.org/#installing

Leave a Reply