CLI / Terminal Access

30-60 minAdvanced

WP-CLI is the official command-line interface for WordPress. It allows you to manage WordPress installations without using a web browser - update plugins, export databases, manage users, and much more. This is the preferred method for developers, agencies, and anyone with SSH access to their server.

Prerequisites

  • SSH access to your server
  • WP-CLI installed (most modern hosts include it)
  • Basic command line knowledge
Easy

Installing CLI

Setting up the environment.

1

Method 1: WP-CLI (Direct)

1

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

2

Make Executable: chmod +x wp-cli.phar

3

Move: sudo mv wp-cli.phar /usr/local/bin/wp

4

Verify: wp --info

Example
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
2

Method 2: Docker (For wp-env)

1

Required for the wp-env workflow.

2

Mac: brew install --cask docker or download Docker Desktop.

3

Windows: Download Docker Desktop for Windows.

4

Linux: sudo apt-get install docker.io

5

Start Docker and verify: docker -v

Example
docker -v
docker-compose -v
3

Method 3: wp-env (Wrapper)

1

Once Docker is running, install the wrapper: npm -g i @wordpress/env

Example
npm -g i @wordpress/env

Verification Checklist

  • wp --info works
  • wp-env start launches site at localhost
  • Database verification: wp post list returns content

Pro Tips

  • Use `--dry-run` with search-replace to test before executing
  • Use `wp-env run cli wp shell` for an interactive PHP shell with WP loaded
  • Alias `wp` to `wp-env run cli wp` for local dev convenience

Common Issues & Fixes

Problem: Error establishing a database connection
Solution: Check wp-config.php matches host/port (often localhost:3306 or db:3306 in Docker)