Skip to content

Commit ffe0e38

Browse files
committed
Document SQLite database storage and DB_PATH
1 parent f9bdc0f commit ffe0e38

4 files changed

Lines changed: 115 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ It is a monorepo that includes the following components:
1414
- **MySQL parser** — An exhaustive MySQL parser with multi-version support.
1515
- [**MySQL on SQLite**](packages/mysql-on-sqlite/) — A MySQL emulation layer on top of SQLite with a PDO-compatible API.
1616
- [**MySQL proxy**](packages/mysql-proxy/) — A MySQL binary protocol implementation to support MySQL-based projects beyond PHP.
17-
- **WordPress plugin** — A plugin that adds SQLite support to WordPress.
17+
- [**WordPress plugin**](packages/plugin-sqlite-database-integration/) — A plugin that adds SQLite support to WordPress.
1818
- **Test suites** — A set of extensive test suites to cover MySQL syntax and functionality.
1919

2020
The monorepo packages are placed under the `packages` directory.

‎bin/build-sqlite-plugin-zip.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rm "$PLUGIN_DIR/wp-includes/database"
2727
cp -R "$DIR/packages/mysql-on-sqlite/src" "$PLUGIN_DIR/wp-includes/database"
2828

2929
# Remove dev-only files.
30+
rm -f "$PLUGIN_DIR/README.md"
3031
rm -rf "$PLUGIN_DIR/composer.json"
3132
rm -rf "$PLUGIN_DIR/vendor"
3233
rm -rf "$PLUGIN_DIR/node_modules"
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# SQLite Database Integration
2+
3+
Run WordPress on SQLite.
4+
5+
## Overview
6+
7+
The plugin provides a `wp-content/db.php` database drop-in powered by
8+
[MySQL on SQLite](../mysql-on-sqlite/). WordPress and plugins continue to use the
9+
`wpdb` API while the driver translates and emulates MySQL queries for SQLite.
10+
11+
## Usage
12+
13+
To set up SQLite, do the following steps in your WordPress admin:
14+
15+
1. Install and activate the plugin.
16+
2. Open **Settings > SQLite integration** and select **Install SQLite database**.
17+
18+
On multisite installs, use Network Admin.
19+
20+
> [!IMPORTANT]
21+
> Enabling SQLite creates a separate SQLite database. It does not migrate data
22+
> from MySQL or MariaDB. Disabling it reconnects WordPress to the original database.
23+
24+
See [readme.txt](readme.txt) for the plugin FAQ and changelog.
25+
26+
## Database storage
27+
28+
By default, the SQLite database is stored in a **randomized path** under
29+
`WP_CONTENT_DIR . '/database'`. The full path is recorded in `db-path.php`
30+
and exposed by the `DB_PATH` constant at runtime.
31+
32+
For example:
33+
34+
1. Database path: `WP_CONTENT_DIR . '/database/.ht.020a33c5d9e5407e8e93b43e55abf62e/.ht.sqlite'`
35+
2. Recorded in: `WP_CONTENT_DIR . '/database/db-path.php'` as `return __DIR__ . '/...';`
36+
3. Exposed by: `DB_PATH`
37+
38+
The random path makes the database location difficult to guess when it is not
39+
otherwise protected.
40+
41+
To properly secure the SQLite database, we recommend defining the `DB_PATH` constant
42+
to an **explicit path** that is protected from public web access. An explicit `DB_PATH`
43+
value is used as-is without randomization. Define it in `wp-config.php`:
44+
45+
```php
46+
// Use protected DB path that is not exposed by the web server.
47+
define( 'DB_PATH', '/private/wordpress/database.sqlite' );
48+
```
49+
50+
> [!CAUTION]
51+
> An explicit `DB_PATH` must point to a **protected** location that your web server
52+
> does not expose. Store the database outside the web root and make sure it's protected.
53+
54+
The value of `DB_PATH` must be an absolute path to the SQLite database file, or `:memory:`
55+
for an in-memory SQLite database. The database directory must be writable by PHP. Changing
56+
`DB_PATH` selects a different database without moving an existing one.
57+
58+
Integrations should always read `DB_PATH` after WordPress loads instead of assuming
59+
a fixed database path.
60+
61+
## Development
62+
63+
Run these commands from the repository root:
64+
65+
```bash
66+
composer install
67+
composer run check-cs
68+
composer run wp-test-sqlite-plugin-php
69+
composer run wp-test-sqlite-plugin-php-multisite
70+
```
71+
72+
See the [repository README](../../README.md#quick-start) for the WordPress test
73+
environment commands.
74+
75+
Build an installable plugin ZIP with:
76+
77+
```bash
78+
composer run build-sqlite-plugin-zip
79+
```
80+
81+
The archive is written to `build/plugin-sqlite-database-integration.zip`.
82+
83+
## Requirements
84+
85+
- **WordPress:** 6.4+
86+
- **PHP:** 7.2+
87+
- **PHP extensions:** `pdo`, `pdo_sqlite`
88+
- **SQLite:** 3.37.0+
89+
90+
## License
91+
92+
SQLite Database Integration is licensed under the
93+
[GNU General Public License v2 or later](LICENSE).

‎packages/plugin-sqlite-database-integration/readme.txt‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
Tags: sqlite, database
1111

12-
Run WordPress on SQLite instead of MySQL or MariaDB.
12+
Run WordPress on SQLite.
1313

1414
== Description ==
1515

@@ -48,6 +48,25 @@ No. Enabling SQLite starts a fresh WordPress installation in a separate database
4848

4949
Disabling the plugin reconnects WordPress to the previous database. Content created while using SQLite is not transferred back.
5050

51+
= Where is the SQLite database stored? =
52+
53+
The default database location is a randomized subdirectory of `wp-content/database/`, such as `wp-content/database/.ht.<random>/.ht.sqlite`. The file `wp-content/database/db-path.php` records its location.
54+
55+
The plugin also defines `DB_PATH` when using randomized storage. Integrations should read it after WordPress loads instead of assuming a fixed database path.
56+
57+
= How can I configure the database location? =
58+
59+
Define `DB_PATH` in `wp-config.php`:
60+
61+
define( 'DB_PATH', '/private/wordpress/database.sqlite' );
62+
63+
**Warning:** An explicit `DB_PATH` must point to a protected location that your web server does not serve. Store the database outside the web root, or configure the web server to block access to the entire database directory.
64+
65+
* Use an absolute path to a file in a directory writable by PHP.
66+
* The path is used as-is, without randomization.
67+
* Changing `DB_PATH` selects a different database; it does not move existing data.
68+
* Use `:memory:` for a temporary database that does not persist.
69+
5170
= What does the plugin require? =
5271

5372
In addition to the WordPress and PHP versions listed above, the plugin requires the PDO SQLite PHP extension and SQLite 3.37.0 or newer. The setup screen also needs write access to the `wp-content` directory and will detect conflicting database drop-ins.

0 commit comments

Comments
 (0)