Installing WP-CLI In a Linux Server

Last Updated on: 

WP-CLI is a command-line interface for WordPress. It can also be used with ClassicPress, as they are no differences in their usage, maybe just minimal if you are updating or downloading new ClassicPress instances.

The benefit of using WP-CLI is that:

  • It makes your life easier with the management of WorpPress or ClassicPress
  • You can regenerate thousand of thumbnails in less time
  • You can backup and or restore database file
  • Manage multiple WP website at once, say you want to install a plugin for multiple website
  • My favourite feature of wp-cli is using search and replace, e.g replacing local devlopment URL with a live one
  • Automate repetitive manual tasks with Cron
  • and lots more

Let’s get started with the installation. First log into your server, and download the WP-CLI phar file using curl or wget:

					

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

or for wget

					

wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Now verify wp-cli is running using: php wp-cli.phar --info

To use WP-CLI from the command line by typing wp, make the file executable and move it to somewhere in your PATH. E.g:

					

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

This path can also be in your $HOME/bin if you have one created already.

Now run wp --infoto confirm everything is in place, you’ll see something as below:

					

user@server:~$ wp --info
OS:     Linux 4.15.0-111-generic #112-Ubuntu SMP Thu Jul 9 20:32:34 UTC 2020 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php7.2
PHP version:    7.2.24-0ubuntu0.18.04.6
php.ini used:   /etc/php/7.2/cli/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:       /home/username
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0
user@server:~$

To Update wp-cli, you simply run wp cli update

In feature guide, we would cover how to use wp-cli with a ClassicPress or WordPress websites, and even go into automating things with bash.

Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php