WordPress WP-CLI FAQ: Interview & Code Review Questions
questions
Answers to common questions about installing, configuring, and deploying WordPress from the command line with WP-CLI, including the correct order of core, config, and database commands. It also covers importing and exporting databases safely, handling failed imports, and why WP-CLI is often preferred over the web installer.
WP-CLI Core Commands
Can I install WordPress in a subdirectory with WP-CLI?
Yes. Pass the full URL including the path to wp core install –url=. Download and config steps stay the same; only the site URL changes.
Used in
- Deploy a New WordPress Site Practice Case
Can I run wp core install without wp config create?
No. WordPress needs database credentials in wp-config.php before installation. Without config, WP-CLI cannot connect to MySQL and the install will fail.
Used in
- Deploy a New WordPress Site Practice Case
Do I always need wp db create?
Only when the database named in wp-config.php does not exist yet. On shared hosting the database is often pre-created — then skip this step. On local dev, create it with WP-CLI.
Used in
- Deploy a New WordPress Site Practice Case
Should I pin a WordPress version when downloading?
For most installs, use the latest stable release without –version. Pin a version only when you intentionally need parity with production or a legacy environment.
Used in
- Deploy a New WordPress Site Practice Case
What directory should I run wp core download in?
Use an empty directory for a fresh site. WP-CLI downloads core files into the current working directory. Mixing with existing files can leave stale plugins or themes from an old project.
Used in
- Deploy a New WordPress Site Practice Case
What happens if I skip wp db create on a new local site?
wp core install fails because MySQL cannot connect to a database that does not exist. The error looks like a credentials problem but the fix is creating the database first.
Used in
- Deploy a New WordPress Site Practice Case
What is the correct order to deploy WordPress with WP-CLI?
Download core (wp core download), create configuration (wp config create), create the database (wp db create), then install (wp core install). Each step depends on the previous one.
Used in
- Deploy a New WordPress Site Practice Case
Why use WP-CLI instead of the web installer?
WP-CLI is scriptable and repeatable — the same commands work on local, staging, and CI pipelines. No browser clicks, no upload limits, and easy to document as code.
Used in
- Deploy a New WordPress Site Practice Case
WP-CLI Database
Does wp db import drop the existing database before importing?
Yes. WP-CLI runs the .sql file against the current database, which typically begins with DROP TABLE IF EXISTS statements for each table. The result is a clean replacement of the existing data, not a merge. This is why the export step before import is critical — anything not in the backup file will not exist after the import.
Used in
- Database Export and Import Practice Case
How do I know the backup I am importing is from the right environment?
Run grep 'siteurl' backup.sql | head -5 before importing. The siteurl value in the dump shows which site and domain the backup came from. If it shows a localhost or staging URL, you will need to run wp search-replace after the import to fix all domain references.
Used in
- Database Export and Import Practice Case
What credentials does wp db import use?
WP-CLI reads the database host, name, user, and password directly from wp-config.php. You do not need to pass credentials on the command line. This is why wp db import backup.sql works without any additional flags.
Used in
- Database Export and Import Practice Case
What if the import fails halfway through?
The database may be in a partially restored state. First, check the error message — it usually points to a specific table or SQL statement. If the import file is valid, try running it again (WP-CLI’s import is generally idempotent for standard WordPress dumps because each table is dropped before recreating). If the file itself is corrupted, you need an earlier backup.
Used in
- Database Export and Import Practice Case
What is the difference between wp db export and a manual mysqldump?
wp db export is a thin wrapper around mysqldump that reads credentials from wp-config.php automatically. The resulting .sql file is compatible with wp db import and standard MySQL import tools. The main advantage over raw mysqldump is that you do not need to manually pass host, user, password, and database name on the command line.
Used in
- Database Export and Import Practice Case
Why run wp core update-db after importing a backup?
The backup captures the database state at the time it was made. If WordPress core or any plugin was updated after that backup, the current PHP code expects a newer schema. wp core update-db applies any pending ALTER TABLE and schema changes that the code expects but the restored database does not yet have.
Used in
- Database Export and Import Practice Case
Smart FAQ Management
4WP FAQ
Not just another FAQ block. A smart wrapper that adds intelligence
without breaking your design.