What is WP-CLI? WP-CLI is an official command line tool that allows you to manage your WordPress sites through a terminal interface. This will enable you to complete your operations in WordPress more practically.
You can easily proceed with many operations such as theme installation, plugin update, and user management, thanks to its user-friendly syntax.
WP-CLI system requirements
Before starting the installation processes, make sure your server meets the minimum requirements for WP-CLI:
- UNIX-like environment (OS X, Linux, FreeBSD, Cygwin; limited support in Windows environment)
- PHP 5.6 or later
- WordPress 3.7 or later (versions older than the latest WordPress release may have degraded functionality)
Firstly, update your server in order to avoid compatibility problems. To do this, use the following command on the terminal screen of your Linux server:
dnf update && dnf upgrade
WP-CLI installation
Step 1: Download the Phar file
After the update process is completed, use the following command in the terminal to install the Phar file for WP-CLI:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Step 2: Make sure it is working
Once it is installed, try to run the Phar file to make sure that the WP-CLI tool is working:
php wp-cli.phar --info
Step 3: Permissions and location
Then proceed with setting the Phar file permissions and carrying it to a more suitable place in the system:
chmod +x wp-cli.phar
sudo mv wp-cli.phar [YOUR PREFERRED LOCATION]
Step 4: See the WP-CLI version
If you want to see the version of the WP-CLI installation, use the following command:
wp --info
Installing a plugin with WP-CLI
You need to switch to the directory where WordPress is installed in order to use WP-CLI commands properly. In our system, the WordPress files are located under the /var/www/html/wp folder.
cd [YOUR WordPress LOCATION]
When you move to the relevant folder, you may want to list the plugins. You can use the following command for this action:
wp plugin list
If you want to search for a plugin in the WordPress repository, the following command will help you:
wp plugin search [PLUGIN NAME]
To install the plugin you have searched for, copy the slug name of it and use it in the following command:
wp plugin install [PLUGIN SLUG NAME]
Activating the plugin you have installed is as easy as the other steps. But you will need the slug name again:
wp plugin activate [PLUGIN SLUG NAME]
You can always check the official WordPress CLI handbook for additional information about the usable commands.