Install WP-CLI to Manage WordPress Site

By Anurag Singh

Updated on May 07, 2025

Install WP-CLI to Manage WordPress Site

In this tutorials, we'll explain how to install WP-CLI to manage WordPress site.

As a website owner, developer, or webmaster, you're probably familiar with managing WordPress sites via the admin dashboard. However, did you know there's an even more efficient way? WP-CLI (WordPress Command Line Interface) is a powerful, lightning-fast tool designed to manage your WordPress site directly from your hosting server’s terminal. It allows you to perform routine tasks quickly, reliably, and without needing to log in through a web browser.

In this guide, we'll walk you through the installation and practical usage of WP-CLI on your hosting account. Let's dive in!

Why WP-CLI?

WP-CLI offers several advantages:

  • Speed and Efficiency: Quickly install plugins/themes, update core files, and manage database operations without navigating multiple pages.
  • Automation and Scripts: Easily automate repetitive tasks through cron jobs or bash scripts.
  • Enhanced Troubleshooting: Resolve issues rapidly with powerful debugging tools directly on your server.

Let's get started!

Prerequisites

Before proceeding, make sure you have the following in place:

  • A Fresh Ubuntu 24.04 dedicated server or KVM VPS.
  • Root or Sudo Privileges: You should have sudo privileges to install packages and make system-wide changes.
  • A Valid Domain Name (Optional but Recommended)

Install WP-CLI to Manage WordPress Site

Step 1: Connect to Your Hosting Server via SSH

First, log in to your hosting server using SSH:

ssh username@your-server-ip

Replace username with your SSH username and your-server-ip with your hosting server IP address.

Step 2: Install PHP, PHP-CLI, and PHP-MySQL

Run the following commands to install PHP and its required extensions:

sudo apt update
sudo apt install php php-cli php-mysql -y

Verify your installation:

php -v

Output:

PHP 8.3.6 (cli) (built: Mar 19 2025 10:08:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Step 3: Install MariaDB

MariaDB is a robust database system fully compatible with MySQL. Install it as follows:

sudo apt install mariadb-server -y

Secure the installation:

sudo mysql_secure_installation

Follow the prompts to secure your MariaDB installation.

Step 4: Create a Database for WordPress

Now, create your WordPress database and user. First, log in to MariaDB:

sudo mysql -u root -p

Create the database, user, and set permissions:

CREATE DATABASE wordpress_db;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace wordpress_db, wpuser, and strong_password with your preferred details.

Installing WP-CLI on Your Hosting Server

Now that all prerequisites are in place, let's install WP-CLI:

Step 5: Download WP-CLI

Before we proceed further, WP-CLI do not allow root user to install and use WP-CLI. We need normal user for that. So, switch to normal user than proceed further.

Download WP-CLI with this command:

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

Step 6: Verify the WP-CLI Installation

Check that WP-CLI downloaded correctly:

php wp-cli.phar --info

This displays WP-CLI details and confirms the download.

Step 7: Make WP-CLI Available Globally

Move WP-CLI to a global location and make it executable:

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

Confirm the global installation:

wp --info

Similar output you will get:

OS: Linux 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
Shell:  /bin/bash
PHP binary: /usr/bin/php8.3
PHP version:  8.3.6
php.ini used: /etc/php/8.3/cli/php.ini
MySQL binary: /usr/bin/mariadb
MySQL version:  mariadb  Ver 15.1 Distrib 10.11.11-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper
SQL modes:  
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: phar:///usr/local/bin/wp
WP-CLI packages dir:  
WP-CLI cache dir: /home/block/.wp-cli/cache
WP-CLI global config: 
WP-CLI project config:  
WP-CLI version: 2.12.0

Congratulations! WP-CLI is now installed.

Using WP-CLI to Manage Your WordPress Site

Here’s how you can leverage WP-CLI to manage your WordPress site quickly and efficiently.

1. Install WordPress Using WP-CLI

Navigate to your public website directory (e.g., /var/www/html):

cd /var/www/html

Then download WordPress and create the configuration file:

wp core download
wp config create --dbname=wordpress_db --dbuser=wpuser --dbpass=strong_password

Now install WordPress:

wp core install --url="yourdomain.com" --title="My WordPress Site" --admin_user="admin" --admin_password="secure_admin_password" --admin_email="youremail@example.com"

Replace placeholders with your actual domain and credentials.

2. Update WordPress Components

Keep your WordPress installation secure and up-to-date easily:

wp core update
wp plugin update --all
wp theme update --all

3. Manage Plugins and Themes

Quickly install and activate plugins or themes:

wp plugin install akismet --activate
wp theme install astra --activate

Deactivate or delete plugins and themes:

wp plugin deactivate akismet
wp plugin delete akismet

4. Database Management

Perform backups and restores effortlessly:

Backup your database:

wp db export wordpress_backup.sql

Restore a database backup:

wp db import wordpress_backup.sql

5. User Management

Efficiently manage users from the command line:

Create a user:

wp user create newuser email@example.com --role=editor --user_pass=password123

Update an existing user’s password:

wp user update newuser --user_pass=newpassword

Automating Routine Tasks

WP-CLI allows you to automate tasks using cron jobs. For instance, to back up your database automatically every day at midnight:

crontab -e

Then add:

0 0 * * * cd /var/www/html && wp db export daily_backup-$(date +\%F).sql

Troubleshooting Common Issues

WP command not found:
Ensure /usr/local/bin is in your PATH variable.

Permission errors:
Make sure WP-CLI is executable (chmod +x) and you're running commands with appropriate permissions.

Database connection errors:
Check your database user, password, and privileges.

Final Thoughts

WP-CLI is a powerful tool that significantly simplifies WordPress administration. By following this guide, you've installed all required tools and learned essential commands to manage your WordPress sites efficiently directly from your hosting server.

Happy WordPress management!

🍪 We use cookies!

This website uses cookies to improve your browsing experience.