Installing WordPress on SQLite

WordPress has a plugin that allows it to run on SQLite instead of MySQL. However, it’s a little weird setting it up – the documented way to set it up is to install WordPress on MySQL, then install and activate the plugin, and then switch to SQLite (which then starts your site off fresh again).

If you were trying to use this plugin to avoid the dependency on MySQL in the first place, these official instructions don’t help you very much. But it turns out to be easy to get it working from the get-go, without MySQL – it’s just not documented particularly well.

Start with a WordPress ZIP freshly extracted. Download the sqlite-database-integration plugin, and extract it to wp-content/plugins. Then two less-obvious steps:

  1. Copy wp-content/plugins/sqlite-database-integration/db.copy to wp-content/db.php. There are some placeholders in this file that the normal installation process does some string-replacement with, but it’s not actually required – a straight copy is fine.
  2. Copy wp-config-sample.php to wp-config.php and rotate the salts. (You can either use the API linked in the comment, or use wp config shuffle-salts from wp-cli.)

If you then go to visit your site, you should be presented with a setup screen to install WordPress, skipping the database setup screen. Sweet! The database is stored in wp-content/database/.ht.sqlite, should you want to inspect it.

Extra: Converting from MySQL to SQLite

This is documented in various places, but just to keep everything together: The plugin to enable SQLite support does not itself help you migrate. There does not seem to be any official way to migrate, but there is a path that seems everyone so far has used without too much difficulty: mysql2sqlite. The README contains all the instructions you need.

Extra: Local WordPress, the Hard Way

I find SQLite to be especially useful for local testing installations, where I may test something once and then put it away, and would rather all the files live in one place rather than be split between the MySQL server and the WordPress directory. Using SQLite makes this super easy, even when doing things “from scratch” rather than using an existing solution like LocalWP.

First you’ll need a you’ll need a PHP installation. If you use a package manager, you could use that. You can build from source, but the dependencies may be onerous without a package manager. Or you can find some other build – I ended up using static-php-cli.

Extract the WordPress ZIP and follow the instructions above to get SQLite set up. You may also want to insert this extra step before completing the setup, to disable e-mails:

  1. Download the latest disable-emails plugin.
  2. Extract it to wp-content/plugins.
  3. Copy wp-content/plugins/disable-emails/mu-plugin/disable-emails-mu.php to wp-content/mu-plugins/disable-emails-mu.php. (You may need to create the wp-content/mu-plugins directory first.)

Then, to serve up your web site, you don’t need a dedicated web server. Just run php -S 127.0.0.1:8000 to start the built-in PHP development web server. You may also consider setting the PHP_CLI_SERVER_WORKERS environment variable to allow concurrent requests (required for subrequests to work) – I like setting it to 4.

Tags: ,

Comments are closed.