wordpress wp-cli
ServerWordpress

Manage WordPress with WP-CLI command line

I often manage WordPress websites through the WP CLI command line interface to save time navigating the web interface, saving time and making it easier to debug in case of errors.

I. Install WP-CLI

WP-CLI is usually pre-installed when you create WordPress through tools like Centminmod, Cyberpanel, Cloudpanel, etc. You can check by going to the WordPress installation directory and typing the command

wp info --allow-rootCode language: Nginx (nginx)

If you don’t see any results, it means that your Server doesn’t have WP-CLI. In this case, install WP-CLI on your server using the following command

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/wpCode language: Nginx (nginx)

If you install WordPress via Docker, you need to add the wpcli declaration to the file. docker-compose.yml similar to below.

  wpcli:
    depends_on:
      - db
      - wordpress
    image: wordpress:cli
    entrypoint: wp
    command: "--info"
    env_file: .env
    volumes:
      - ./wordpress/html:/var/www/htmlCode language: YAML (yaml)

You can refer to the example in the article on how to install WordPress using Caddy .

Below is a summary of commonly used WP CLI commands so that you can find them again in case you forget them.

II. Plugin Management

Show list of all available plugins

wp plugin listCode language: PHP (php)

Show active plugins

wp plugin list --status=activeCode language: PHP (php)

Show plugins with new updates available

wp plugin list | grep "available" | awk '{print $1}' 
wp plugin list | grep "available" | awk '{print $1}' ORS=' ' Code language: Nginx (nginx)

Install, activate, update, deactivate and delete new plugins, for example Advanced Custom Fields

wp plugin install advanced-custom-fields 
wp plugin activate advanced-custom-fields 
wp plugin update advanced-custom-fields 
wp plugin deactivate advanced-custom-fields 
wp plugin delete advanced-custom-fields 
Code language: Nginx (nginx)

Update all plugins

wp plugin update --allCode language: Nginx (nginx)

III. Theme management

Show theme list

wp theme listCode language: PHP (php)

Update theme, for example Kadence

wp theme update kadenceCode language: Nginx (nginx)

IV. Database management

Backup database

wp db exportCode language: JavaScript (javascript)

Restore database

wp db import Code language: JavaScript (javascript)

Access the database CLI to type commands

wp db cliCode language: Nginx (nginx)

V. Change website URL

This command is used when you need to create a staging site for the main website, change from domain A to domain B, or vice versa.

wp search-replace 'https://markknow.dev' 'https://markknow.com' --skip-columns=guidCode language: Nginx (nginx)

VI. Using WP-CLI via Docker

In case of using WP-CLI via docker, the commands need to be changed to

docker-compose run --rm wpcli commandCode language: Dockerfile (dockerfile)

Command example

wp plugin listCode language: PHP (php)

should be replaced by

 docker-compose run --rm wpcli wp plugin list --allow-rootCode language: Dockerfile (dockerfile)

This command needs to be executed in the directory containing the file. docker-compose.yml WordPress setup.


There are many other WP-CLI commands, you can refer to them with the following command.

wp --helpCode language: Bash (bash)

If my article provides useful information and knowledge to you, don’t hesitate to invite me for a beer to have more motivation to share more. Thank you!

Comment Policy: We truly value your comments and appreciate the time you take to share your thoughts and feedback with us.

Note: Comments that are identified as spam or purely promotional will be removed.

To enhance your commenting experience, consider creating a Gravatar account. By adding an avatar and using the same e-mail here, your comments will feature a unique and recognizable avatar, making it easier for other members to identify you.

Please use a valid e-mail address so you can receive notifications when your comments receive replies.

Related posts

Fix WireGuard VPN (wg-easy) not working on Oracle Cloud VPS

Mark Lee

Portfolio Setup – A WordPress Guide

Mark Lee

Instructions for installing Squid as a Proxy Server on Oracle Cloud VPS

Mark Lee

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More