How to Install WP-CLI: Complete Guide for Windows, macOS, and Linux

When it comes to creating a WordPress website, there are several important implementations to consider. But some tasks are often repetitive, which can make you feel a bit bogged down. Manually installing plugins, updating themes, or managing user accounts can eat into your valuable time. Thankfully, there’s a powerful solution: WP-CLI.

This command-line interface is dedicated for WordPress websites. With it, you can automate repetitive tasks for a better focus on the creative aspects of building incredible websites.

But how do you install WP-CLI? Well, expert WordPress developers go about it a few different ways. We’ll discuss them through this blog.

What is WP-CLI?

WP-CLI, or WordPress Command Line Interface, is a powerful command-line tool designed to simplify WordPress site development and management. You can perform a wide array of tasks directly from the terminal or command prompt, so there is no need for a web browser.

WP-CLI can handle functions such as

Apart from these, WP-CLI can also help with managing users, executing database operations, and configuring multisite installations.

By allowing developers and administrators to automate repetitive tasks, WP-CLI significantly streamlines the workflow, enhancing productivity and efficiency. It is particularly useful for those managing multiple WordPress sites.

With WP-CLI, complex operations can be executed with a single command. That’s why WordPress development services use it for modern website development and maintenance.

Why Use WP-CLI?

WP-CLI is outstanding for a WordPress website due to a few critical reasons. Here are a few:

Efficiency

WP-CLI shines in its ability to automate repetitive tasks. Imagine installing and activating multiple plugins with a single command, instead of clicking through the plugin directory for each one. Its time-saving aspect makes it one of the key tools for managing multiple WordPress sites.

Power and Control

WP-CLI unlocks functionalities beyond the WordPress admin dashboard. You can perform complex database operations, search and replace content across your site, or even schedule automated tasks – actions not readily available in the standard interface.

Scripting and Automation

WP-CLI allows you to create scripts that automate entire workflows. This is particularly useful for developers who frequently perform similar actions on multiple sites.  Imagine a script that sets up a new WordPress site with your preferred theme, plugins, and configurations – all with a single command.

Remote Management

With WP-CLI, you can manage your WordPress sites remotely without needing to log in to the admin panel on each server. This is a huge advantage for developers and agencies who manage a portfolio of client websites.

Version Control Integration

Since WP-CLI interacts with your site’s core files and database, it integrates seamlessly with version control systems like Git. This allows you to track changes, revert to previous versions, and collaborate more effectively on development projects.

While the WordPress admin interface is user-friendly, WP-CLI offers a powerful and efficient alternative for your website.

Need help with a streamline WordPress website development and management?

How to Install WP-CLI?

You can install WP-CLI for your WordPress website with ease, whether it’s for Windows, macOS, or Linux. Here’s how the process goes.

For Windows

Before installing WP-CLI, make sure you have PHP installed on your system. Most web hosting providers include PHP by default. Create a simple phpinfo.php file in your WordPress root directory structure and access it in your browser.

Step 1: Visit the official WP-CLI downloads page and download the latest Phar archive specifically for Windows.

Step 2: While you can use the Phar file directly, some users prefer to extract it for easier management. You can use a tool like WinRAR or 7-Zip to extract the contents.

Step 3: Set PATH environment variable to run WP-CLI commands from any directory in your command prompt. Search for and click on “Edit the system environment variables” to open the System Properties window, and then click the “Environment Variables” button.

Under “System variables”, find the variable named “Path” and click “Edit”. Enter the full path to the directory containing the WP-CLI Phar file (or the extracted folder if you choose to extract it).

Step 4: Open your command prompt and navigate to the directory containing the WP-CLI Phar file (or the extracted folder if you choose to extract it). Here, you can start using WP-CLI commands by prefixing them with wp.

For example, wp core version will display the current WordPress version of your site.

For macOS/Linux

When it comes to installing WP-CLI on macOS and Linux, there are a few prerequisites to consider:

  • UNIX-like environment: macOS and Linux are both UNIX-like operating systems, making them compatible with WP-CLI.
  • PHP 5.6 or later: Ensure you have PHP installed on your system and accessible from the command line. You can usually verify this through your terminal or by checking with your hosting provider.
  • cURL: cURL is a command-line tool for transferring data. Most macOS and Linux systems come with cURL pre-installed. You can verify its presence by running curl –version in your terminal. If not installed, refer to your distribution’s package manager for installation instructions.

Step 1: Open your terminal. This is where you’ll interact with the command line. You can usually find the terminal application by searching for “Terminal” in your applications list.

Step 2: Run the following command in your terminal, replacing v2.20.0 with the latest WP-CLI version number (you can find this on the WP-CLI download page):

curl -O https://raw.githubusercontent.com/wp-cli/wp-cli/v2.20.0/bin/wp-cli.phar

Step 3: Make the file executable. Here’s the command for the same:

chmod +x wp-cli.phar

Step 4: It’s time to verify the installation. Open your terminal, type wp –version, and press Enter. If the installation was successful, you should see the current WP-CLI version number displayed.

While the recommended method uses cURL, alternative installation methods include Composer and Homebrew (for macOS). These cater to specific use cases and might require additional setup.

How to Use WP-CLI?

WP-CLI offers a vast array of commands to manage your WordPress site directly from the command line. Here’s the basic command structure.

wp [command] [subcommand] [options] [arguments]
  • wp: This is the core prefix that identifies the command-line tool as WP-CLI.
  • [command]: This specifies the main action you want to perform. For example, core for core WordPress functionality, plugin for managing plugins, or user for user management.
  • [subcommand] (optional): This further refines the action within a command. For instance, install within the plugin command lets you install plugins.
  • [options] (optional): These are flags that modify the behavior of the command. Options usually start with a double hyphen (–) followed by the option name and sometimes a value.
  • [arguments] (optional): These provide specific details for the command. For example, the plugin install command might require the name of the plugin you want to install as an argument.

Common WP-CLI Commands

Let’s take a look at some of the commonly-used WP-CLI commands:

  • wp core update: Updates your WordPress core to the latest version.
  • wp core version: Checks the current WordPress version of your site.
  • wp plugin install <plugin-name>: Installs a new plugin from the WordPress repository.
  • wp plugin activate <plugin-name>: Activates a plugin on your site.
  • wp plugin deactivate <plugin-name>: Deactivates a plugin on your site.
  • wp theme activate <theme-name>: Activates a theme on your site.
  • wp theme list: Lists all installed themes.
  • wp user create <username> <email>: Creates a new user on your site.
  • wp user list: Lists all users on your site.

Consult with our WordPress development agency if you want to streamline the workflow beyond these commands.

FAQs on Installing WP-CLI

How do I verify a successful installation?
Open your terminal (Windows) or command prompt (macOS/Linux) and type wp --version. If successful, you'll see the current WP-CLI version.
I don't have cURL installed. How do I get it?
cURL is usually pre-installed on most macOS and Linux systems. You can verify its presence by running curl --version in your terminal. If not installed, consult your distribution's documentation for installation instructions.
Is WP-CLI safe to use?
Yes, WP-CLI is a safe and secure tool to use. It is regularly updated and maintained by a team of developers, making sure it is free from any security vulnerabilities. However, as with any tool, it is essential to use it responsibly and follow best practices to avoid any risks.

Conclusion

WP-CLI can be a game-changer for anyone creating a WordPress website. With it, you can automate tasks, manage your site remotely, and unlock functionalities beyond the traditional admin panel.

To install WP-CLI, you will need to have access to a command-line interface and a WordPress website. And there are alternative methods like Composer and Homebrew (macOS) for specific use cases.

If you need help with implementing and using WP-CLI along with other tactics to simplify the development process, consult with our WordPress experts today!

Want the best services for your WordPress project?

author
Mehul Patel is a seasoned IT Engineer with expertise as a WordPress Developer. With a strong background in Core PHP and WordPress, he has excelled in website development, theme customization, and plugin development.

Leave a comment