WordPress SQLite DB Integration
A recent twitter interaction prompted me to explore the SQLite database integration plugin for WordPress. I have previously used its predecessors, wp-sqlite-db and sqlite-integration. Unfortunately, the community plugin lacks installation instructions and has broken the method for installation via Composer and koodimonni/composer-dropin-installer
.
Installation
The primary issue, and a reason for potential inclusion in core, is that installing plugins requires a running WordPress system, which in turn needs a database. It is possible to bypass the intermediary MySQL/MariaDB database, which is only necessary for the plugin installation. Minimal configuration involves only two steps:
- Download and unzip the plugin from this link.
- Move the
db.php
drop-in file.
Assuming you’re operating from the root of your installation and keep plugins in wp-content
, here’s a straightforward script:
#!/bin/bash
# Define variables
PLUGIN_URL="https://downloads.wordpress.org/plugin/sqlite-database-integration.zip"
PLUGIN_ZIP="sqlite-database-integration.zip"
PLUGIN_DIR="wp-content/plugins"
DB_COPY_SRC="$PLUGIN_DIR/sqlite-database-integration/db.copy"
DB_COPY_DEST="wp-content/db.php"
# Download the plugin zip file
curl -o $PLUGIN_ZIP $PLUGIN_URL
# Unzip the plugin to the plugins directory
unzip -o $PLUGIN_ZIP -d $PLUGIN_DIR
# Copy the db.copy to the destination
cp $DB_COPY_SRC $DB_COPY_DEST
# Clean up by removing the downloaded zip file
rm $PLUGIN_ZIP
Configuration
There are additional steps to consider, such as placing the database file above the public root directory. Unfortunately, the plugin documentation does not cover this:
- Although the
db.php
drop-in file sets this constant if it’s not defined, I would setconst DB_ENGINE = 'sqlite';
. - Examine the
db.php
drop-in. It sets two variables when copied by the plugin. Since we don’t yet have a WordPress installation, it defaults to standard settings. - Set the following constants if you want to store the database in a different location:
FQDBDIR
- This is the database directory where your *.sqlite will be saved. It defaults to a
database
directory in theWP_CONTENT_DIR
. FQDB
- This is the name of the database file. Default
.ht.sqlite
.
Typically, my wp-config.php
file is one level above the web root of my site, and thus I would place the database directory there as well. Ensure the location is writable by the application.
const DB_ENGINE = 'sqlite';
const FQDBDIR = __DIR__ . '/database';
Conclusion
By following the two simple steps mentioned above, you can utilize an SQLite database in WordPress without the need for an intermediary MySQL/MariaDB database.
Check out Duane‘s project https://notwp.org/. An attempt at creating an alternative WordPress plugin directory.