How to Install and Use WordPress CLI (Wp-Cli)

WordPress CLI, or wp-cli, is a powerful command-line tool that allows you to manage your WordPress websites directly from the terminal. It’s particularly useful for tasks like plugin installation, theme management, and database maintenance. In this guide, we’ll walk you through the installation and basic usage of wp-cli on a Linux system.

Prerequisites

Before you begin, ensure that you have the following prerequisites in place:

  1. Linux System: This guide assumes you are using a Linux-based operating system.

  2. Terminal Access: You should have access to a terminal or command-line interface.

  3. Superuser Privileges: You need superuser or sudo privileges to install software globally on your system.

Installation

Follow these steps to install WordPress CLI:

  1. Open your terminal.

  2. Update the package list to ensure you have the latest information about available packages:

    1
    
    sudo apt update
  3. Install the less utility. While it’s not required for WordPress CLI, it’s useful for viewing long text files and is often a recommended addition:

    1
    
    sudo apt install less
  4. Download the WordPress CLI executable (wp-cli.phar) from the official GitHub repository using curl:

    1
    
    curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  5. Make the wp-cli.phar file executable:

    1
    
    chmod +x wp-cli.phar
  6. Move the wp-cli.phar file to a directory in your system’s PATH to make it globally accessible:

    1
    
    sudo mv wp-cli.phar /usr/local/bin/wp
  7. Create a configuration directory for WordPress CLI and assign ownership to the www-data user (the web server user):

    1
    2
    
    sudo mkdir /var/www/.wp-cli
    sudo chown -R www-data:www-data /var/www/.wp-cli

Basic Usage

Now that WordPress CLI is installed, you can use it to manage your WordPress site from the command line. Here are some common commands:

  1. Navigate to Your WordPress Root Directory:

    Before running any WordPress CLI commands, navigate to the root directory of your WordPress installation:

    1
    
    cd /path/to/your/wordpress/directory
  2. List Installed Plugins:

    To list all the plugins currently installed on your WordPress site, use the following command:

    1
    
    wp plugin list

    This will display a list of active and inactive plugins, along with their status and version information.

That’s it! You’ve successfully installed WordPress CLI and used it to list your installed plugins. You can explore more commands and features by checking out the official documentation.

WordPress CLI can save you time and simplify various WordPress management tasks, making it a valuable tool for website administrators and developers.

0%