The classic WordPress “5‑minute install” works, but it’s repetitive: upload files, create a config, click through the web installer, then repeat the same post‑install steps (permalinks, a theme, plugins…). WP‑CLI collapses that workflow into a handful of commands—fast, consistent, and easy to automate.
Even better: WP‑CLI can prompt you interactively so you don’t have to remember (or mistype) every flag.
What you’ll need
- A Linux server with PHP and typical WordPress extensions installed
- MySQL/MariaDB
- A domain mapped to your server with a working web root (docroot)
- SSH access
Tip: For best security and fewer permission headaches, run WP‑CLI as the same user that owns the site files (often a per‑site user, or
www-data).
Step 1: Install WP‑CLI
Download the WP‑CLI Phar, verify it runs, and place it on your PATH:
|
1 2 3 4 5 6 |
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 wp --info |
Step 2: Go to your site directory
Move into your site’s docroot (examples):
/var/www/example.com/public_html/var/www/example.com/html
|
1 2 |
cd /var/www/example.com/public_html |
If your web files are owned by www-data, you can run:
|
1 2 |
sudo -u www-data -H wp --info |
Step 3: Create a database and DB user
Create a dedicated database + user for this WordPress site.
|
1 2 |
mysql -u root -p |
Then in the MySQL prompt:
|
1 2 3 4 5 6 |
CREATE DATABASE wp_example DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD_HERE'; GRANT ALL PRIVILEGES ON wp_example.* TO 'wp_user'@'localhost'; FLUSH PRIVILEGES; EXIT; |
Step 4: Download WordPress core
|
1 2 |
wp core download --locale=en_US |
Step 5: Create wp-config.php
Generate your config with WP‑CLI:
|
1 2 3 4 5 6 7 |
wp config create \ --dbname=wp_example \ --dbuser=wp_user \ --dbpass='STRONG_PASSWORD_HERE' \ --dbhost=localhost \ --dbprefix=wp_ |
Step 6: Run the WordPress install
This creates the tables and the initial admin user:
|
1 2 3 4 5 6 7 |
wp core install \ --url="https://example.com" \ --title="My Site Title" \ --admin_user="admin" \ --admin_password="A_DIFFERENT_STRONG_PASSWORD" \ --admin_email="you@example.com" |
Step 7: Set pretty permalinks (common post‑install step)
|
1 2 3 |
wp rewrite structure '/%postname%/' --hard wp rewrite flush --hard |
Make it painless: use interactive prompts
The annoying part of WP‑CLI isn’t the commands—it’s remembering and typing the flags precisely.
WP‑CLI has a built‑in fix: --prompt.
Prompt for anything you didn’t specify
|
1 2 |
wp core install --prompt |
Prompt only for sensitive values (like passwords)
This keeps secrets out of shell history and reduces copy/paste mistakes:
|
1 2 |
wp config create --dbname=wp_example --dbuser=wp_user --prompt=dbpass |
Bonus: stop retyping flags with wp-cli.yml
If you’re always passing things like --path=/var/www/..., set defaults once with a local config file.
Create a wp-cli.yml in your site directory:
|
1 2 |
path: /var/www/example.com/public_html |
Now you can run WP‑CLI from anywhere without repeatedly specifying --path.
Troubleshooting quick hits
- “This does not seem to be a WordPress installation” → you’re in the wrong directory;
cdinto the docroot where you ranwp core download. - Permission errors → run WP‑CLI as the site owner user, and ensure ownership/permissions are correct.
- Missing PHP extensions → install the required modules and restart PHP‑FPM/Apache.
Wrap‑up
With WP‑CLI you can install WordPress in minutes—and with --prompt and wp-cli.yml, you can make it feel like a repeatable, low‑friction “installer wizard” you can use again and again.




