You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Documentation] Adding troubleshooting sections for WP-CLI database connections (#2333)
## Motivation for the change, related issues
Issue #2332 identified a scenario where additional steps are required to
mount WP-CLI with a mounted playground. This pull request adds a guide
for the user to run `WP-CLI` command successfully with WordPress
Playground.
## Implementation details
- Adds a new troubleshooting section to
/blueprints/troubleshoot-and-debug detailing how to resolve "Error
establishing a database connection".
- Includes a corresponding Blueprint example in /blueprints/examples for
quick reference.
## Testing Instructions (or ideally a Blueprint)
- Download the branch `adding-blueprints-tips`.
- Install the node dependencies.
- Run the documentation `npm run dev:docs`
---------
Co-authored-by: Bero <[email protected]>
Co-authored-by: Adam Zieliński <[email protected]>
Copy file name to clipboardExpand all lines: packages/docs/site/docs/blueprints/08-examples.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,24 @@ blueprint={{
86
86
]
87
87
}} />
88
88
89
+
## How to work with WP-CLI from the terminal and Playground
90
+
91
+
You can run WP-CLI commands on a Playground instance either from your terminal or directly within a Blueprint.
92
+
93
+
To use your terminal, you must first mount the `/wordpress/` directory and ensure the SQLite database integration is configured. This is because Playground's internal database doesn't persist on a mounted site, so you must explicitly install the database plugin via a Blueprint. This allows WP-CLI to recognize the WordPress installation and connect to its database.
94
+
95
+
:::note
96
+
If you run WP-CLI commands as steps within your Blueprint file, this manual setup is not needed.
97
+
:::
98
+
99
+
The following Blueprint snippet handles this setup:
100
+
101
+
<BlueprintExample blueprint={{
102
+
"plugins": [ "sqlite-database-integration" ]
103
+
}} />
104
+
105
+
For a detailed explanation of why this is needed, refer to the [Troubleshoot and Debug Blueprints](/blueprints/troubleshoot-and-debug#wp-cli-error-establishing-a-database-connection-on-mounted-sites) section.
Copy file name to clipboardExpand all lines: packages/docs/site/docs/blueprints/09-troubleshoot-and-debug-blueprints.md
+31-2Lines changed: 31 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,36 @@ When you build Blueprints, you might run into issues. Here are tips and tools to
11
11
## Review Common gotchas
12
12
13
13
- 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"`.
14
-
- 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}`.
14
+
15
+
## Common Issues and Solutions
16
+
17
+
### WP-CLI: Error Establishing a Database Connection on Mounted Sites
18
+
19
+
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.
20
+
21
+
To resolve this, you need to explicitly install and configure the SQLite database integration plugin within your Blueprint.
22
+
23
+
**Solution:** Add the following steps to your Blueprint:
24
+
25
+
```json
26
+
{
27
+
"plugins": [ "sqlite-database-integration" ]
28
+
}
29
+
```
30
+
31
+
**Example Usage:**
32
+
33
+
To test this locally, combine the Blueprint with your Playground CLI command:
34
+
35
+
```bash
36
+
mkdir wordpress
37
+
# Ensure your blueprint with the above steps is saved as, for example, './blueprint.json'
38
+
npx @wp-playground/cli server --mount-before-install=wordpress:/wordpress --blueprint=./blueprint.json
39
+
cd wordpress
40
+
wp post list
41
+
```
42
+
43
+
This will ensure the SQLite plugin is installed correctly and configured within your mounted WordPress site, allowing `wp-cli` commands to function correctly.
15
44
16
45
## Blueprints Builder
17
46
@@ -46,7 +75,7 @@ Full list of methods we can use is available [here](/api/client/interface/Playgr
46
75
47
76
## Check for errors in the browser console
48
77
49
-
If your Blueprint isn’t running as expected, open the browser developer tools to see if there are any errors.
78
+
If your Blueprint isn’t running as expected, open the browser developer tools to check for any errors.
50
79
51
80
To open the developer tools in Chrome, Firefox, Safari\*, and Edge: press `Ctrl + Shift + I` on Windows/Linux or `Cmd + Option + I` on macOS.
0 commit comments