|
| 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). |
0 commit comments