Troubleshoot and debug Blueprints
When you build Blueprints, you might run into issues. Here are tips and tools to help you debug them:
Review Common gotchas
- Require
wp-load: to run a WordPress PHP function using therunPHPstep, you’d need to require wp-load.php. So, the value of thecodekey should start with"<?php require_once('wordpress/wp-load.php'); REST_OF_YOUR_CODE".
Common Issues and Solutions
WP-CLI: Error Establishing a Database Connection on Mounted Sites
When using wp-cli with a mounted Playground site (e.g., via --mount-before-install), you might encounter an "Error establishing a database connection." This happens because WordPress Playground loads the SQLite database integration plugin from its internal files by default, not from the mounted directory, meaning it's not persisted for external wp-cli calls.
To resolve this, you need to explicitly install and configure the SQLite database integration plugin within your Blueprint.
Solution: Add the following steps to your Blueprint:
{
"plugins": [ "sqlite-database-integration" ]
}
Example Usage:
To test this locally, combine the Blueprint with your Playground CLI command:
mkdir wordpress
# Ensure your blueprint with the above steps is saved as, for example, './blueprint.json'
npx @wp-playground/cli server --mount-before-install=wordpress:/wordpress --blueprint=./blueprint.json
cd wordpress
wp post list
This will ensure the SQLite plugin is installed correctly and configured within your mounted WordPress site, allowing wp-cli commands to function correctly.