-
Notifications
You must be signed in to change notification settings - Fork 327
[Documentation] Adding troubleshooting sections for WP-CLI database connections #2333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 1 commit
4c80717
5b4fb6f
0ecbc2f
eb23194
4c76c63
095d44a
4ea9255
2d8e6c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,54 @@ When you build Blueprints, you might run into issues. Here are tips and tools to | |
|
||
- Require `wp-load`: to run a WordPress PHP function using the `runPHP` step, you’d need to require [wp-load.php](https://github.com/WordPress/WordPress/blob/master/wp-load.php). So, the value of the `code` key should start with `"<?php require_once('wordpress/wp-load.php'); REST_OF_YOUR_CODE"`. | ||
- Enable `networking`: to access wp.org assets (themes, plugins, blocks, or patterns), or load a stylesheet using [add_editor_style()](https://developer.wordpress.org/reference/functions/add_editor_style/) (say, when [creating a custom block style](https://developer.wordpress.org/news/2023/02/creating-custom-block-styles-in-wordpress-themes)), you’d need to enable the `networking` option: `"features": {"networking": true}`. | ||
- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above, the way this is worded makes it sound like you can run WP-CLI from non-mounted sites, which I don't think you can. (Happy to be proven wrong). My experience was that I needed to mount /wordpress/ locally to get WP-CLI working, so the documentation should rather be reframed around "How to get WP-CLI working with Playground" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jonathanbossenger does it read better now? I saw @fellyph added a relevant commit after this interaction |
||
|
||
## 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, not from the mounted directory, meaning it's not persisted for external `wp-cli` calls. | ||
fellyph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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: | ||
|
||
```json | ||
{ | ||
"steps": [ | ||
{ | ||
"step": "installPlugin", | ||
"pluginData": { | ||
"resource": "wordpress.org/plugins", | ||
"slug": "sqlite-database-integration" | ||
} | ||
}, | ||
{ | ||
"step": "cp", | ||
"fromPath": "/wordpress/wp-content/plugins/sqlite-database-integration/db.copy", | ||
"toPath": "/wordpress/wp-content/db.php" | ||
}, | ||
{ | ||
"step": "activatePlugin", | ||
"pluginPath": "/wordpress/wp-content/plugins/sqlite-database-integration" | ||
} | ||
] | ||
fellyph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
``` | ||
|
||
**Example Usage:** | ||
|
||
To test this locally, combine the Blueprint with your Playground CLI command: | ||
|
||
```bash | ||
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. | ||
|
||
## Blueprints Builder | ||
|
||
|
@@ -45,7 +93,7 @@ Full list of methods we can use is available [here](/api/client/interface/Playgr | |
|
||
## Check for errors in the browser console | ||
|
||
If your Blueprint isn’t running as expected, open the browser developer tools to see if there are any errors. | ||
If your Blueprint isn’t running as expected, open the browser developer tools to check for any errors. | ||
|
||
To open the developer tools in Chrome, Firefox, Safari\*, and Edge: press `Ctrl + Shift + I` on Windows/Linux or `Cmd + Option + I` on macOS. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question (asking because I'm not sure): Is this only relevant to mounted sites? What I mean is, can you run WP-CLI commands on a non-mounted site?
I don't think you can, so it might be useful to reframe this around how to run WP CLI commands on a playground instance, ie, you need to mount the /wordpress/ folder, and also configure the SQLite integration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the section. You are right, the point is how to connect the playground with the WP-CLI.