WordPress is an open-source easy-to-use content management system. It powers the largest number of websites in the world. Due to its easy-to-use interface and high level of customization, people have been using it for years.
It provides a dashboard from which you can manage everything easily. For instance, you can install plugins and themes or update content/site, etc. It is a GUI (graphical user interface) that even a beginner can understand easily.
But do you know WordPress also provides a command line interface? You can use it to do everything you do with your hosting or admin dashboard.
It’s a handy tool that every developer should know and use. Understanding it helps in enhancing workflow. This guide will walk you through installing and configuring WP-CLI, including step-by-step instructions. Additionally, we will give you practical examples, and tips for ensuring seamless setup and usage.
What is WP-CLI?
WP-CLI as the name suggests is a command line interface. It allows you to perform all the tasks that you perform with the dashboard. But here is a catch as you are using a CLI you can do all this without accessing the dashboard.
It’s an open-source project that developers around the world maintain. Talking about the compatibility it runs on OS that are unix based. For example Linux, MacOS, and Windows.
Advantages of WP-CLI
Using WP-CLI has a lot of advantages over the regular GUI method. Every developer should know about it as it can take WordPress development to a whole new level. Below I have mentioned the most prominent ones.
1. Fast and efficient
If you have used any command line tool you already know how quickly you can perform tasks. You don’t have to wander here and there and do manual operations. This way you can perform tasks much faster.
2. Better Security
Using WP-CLI gives you an edge in terms of security. It allows you to manage and update everything which results in better security.
3. Automation
WP-CLI allows you to automate various tasks that otherwise take a lot of time traditionally. This way you get more time to perform other crucial tasks without having to worry about tasks like backup and updates etc.
Requirements to Run WP-CLI
Before learning about the usage, you must understand the requirements. So that you can use WP-CLI without any issues. We have mentioned the requirements below.
- Operating System: WP-CLI supports UNIX-based systems like Linux and macOS. Windows can also run it but the control is not as much as in the other two. That’s why we recommend using a Linux subsystem like WSL.
- PHP version: the recommended PHP version is 7 or above but it can run on 5.6 or later versions.
- WordPress: Version 3.7 or higher is compatible with running WP-CLI.
How to install WP-CLI
We will learn the installation and then later head on to command execution. Nonetheless, we have more than one method of installation. So let’s understand them in detail.
The WordPress Recommended Method
This method is recommended by WordPress itself. Here what you have to do is download the Phar build(these are archives similar to JAR files). This way you will mark it as executable while placing it on the path.
- Step 1 Download: The first step is to install and download the wp-cli.phar. You can do so by using wget or curl –
123curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar - Step 2 Check working: You can check if its working or not by execut–ing the following command –
123php wp-cli.phar --info - Make File Executable: If you don’t want to use php wp-cli.phar, you can make the file executable and move it in the path.
1234sudo mv wp-cli.phar /usr/local/bin/wpchmod +x wp-cli.phar
Now you can check if it is installed successfully by running wp –info, you will see the output as mentioned below in case of successful installation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
OS: Linux 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64 Shell: /usr/bin/zsh PHP binary: /usr/bin/php PHP version: 7.1.12-1+ubuntu16.04.1+deb.sury.org+1 php.ini used: /etc/php/7.1/cli/php.ini MySQL binary: MySQL version: SQL modes: WP-CLI root dir: /home/wp-cli/.wp-cli WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/ WP-CLI global config: /home/wp-cli/.wp-cli/config.yml WP-CLI project config: WP-CLI version: 1.5.0 |
That’s it now you have successfully installed WP-CLI in WordPress.
How to Update WP-CLI
After successful installation, another step is to update the WP-CLI. If you have installed it using the Phar method you can simply update it with the CLI update. If it is owned by root then you have to make a slight modification. Instead of using wp-cli update use sudo wp-cli-update. While installing the WP-CLI you will see a prompt with an option to accept and decline.
1 2 3 |
You have version 0.21.1. Would you like to update to 0.23.1? [y/n] |
You can decide what to do, most likely you may want to update so go with yes. After a successful update, you will see a success message like this.
Success: Updated WP-CLI to 0.23.1
On the other hand, if there is no update available or you are on the latest version itself the message you will see will be like this.
WP-CLI is the latest version.