In this tutorials, we'll explain how to install WP-CLI to manage WordPress site.
Intruduction
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!
Let's get started!
Prerequisites
Before proceeding, make sure you have the following in place:
- A Fresh Debian 13 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)
- Replace
example.comwith your domain name.
Learn how to install WP-CLI to manage WordPress site on Debian 13.
1. Install Required Packages
sudo apt update
sudo apt install nginx mariadb-server php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip unzip curl certbot python3-certbot-nginx -y
Check PHP version:
php -v
ls /run/php/
You should see something like php8.4-fpm.sock.
2. Setup Database
sudo mysql_secure_installation
Login into MariaDB:
sudo mariadb
Create database:
CREATE DATABASE newsite;
CREATE USER 'newsiteuser'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
GRANT ALL PRIVILEGES ON newsite.* TO 'newsiteuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
3. Install WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Test:
wp --info
Similar output you will get:
OS: Linux 6.12.57+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1 (2025-11-05) x86_64
Shell: /bin/bash
PHP binary: /usr/bin/php8.4
PHP version: 8.4.16
php.ini used: /etc/php/8.4/cli/php.ini
MySQL binary: /usr/bin/mariadb
MySQL version: mariadb from 11.8.3-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
SQL modes: STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
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: /root/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.12.0
4. Download & Configure WordPress
sudo mkdir -p /var/www/newsite
sudo chown -R $USER:$USER /var/www/newsite
cd /var/www/newsite
Now download:
wp core download
wp config create --dbname=newsite --dbuser=newsiteuser --dbpass=StrongPasswordHere
Install WordPress:
wp core install \
--url="http://example.com" \
--title="My WordPress Site" \
--admin_user=admin \
--admin_password=StrongAdminPassword \
--admin_email=admin@example.com
Note: Replace --url with your domain name. Replace --admin_user, --admin_password, and --admin_email value with your value because this will use for admin login.
Fix ownership:
sudo chown -R www-data:www-data /var/www/newsite
5. Configure Nginx
Create config:
sudo nano /etc/nginx/sites-available/newsite.conf
Paste:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/newsite;
index index.php index.html;
access_log /var/log/nginx/newsite.access.log;
error_log /var/log/nginx/newsite.error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff2)$ {
expires max;
log_not_found off;
}
}
Note: Replace php8.4-fpm.sock with your php sock.
Enable site:
sudo ln -s /etc/nginx/sites-available/newsite.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
6. Generate SSL Certificate
sudo certbot --nginx -d example.com -d www.example.com
Choose redirect to HTTPS.
Auto-renew test
sudo certbot renew --dry-run
7. Access domain
Navigate to your browser and access:
https://example.com
Use full commands:
1. WordPress URLs if needed:
sudo -u www-data wp option update siteurl "https://example.com"
sudo -u www-data wp option update home "https://example.com"
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
We have seen how to install 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!

