WordPress and SQLite

When you install WordPress, one of the installation requirements is to have a MySQL database, therefore you’re restricted to that particular engine. However, it’s possigle to use SQLite 3 as an alternative.

To give a little context, some time ago existed (well it still exists) a plugin called PDO for WordPress which allowed the integration aforementioned in a painless way. The bas side if this is that this plugin hasn’t been updated in years and because of that its compatibility with newer versions is obscure to say the least and may require some modifications to the code (I remember is tested it with WordPress 3.6 and it worked). The good part is that now we have an alternative.

SQLite Integration

It’s a WordPress plugin that allows you to replace the default engine to use SQLite instead of MySQL. Unlike a traditional plugin, you mustn’t install it once the CMS is already running but before this (when you copy the files to be precise), otherwise you won’t be able to use SQLite. It must be noted that you won’t be allowed to choose the engine but this is replaced completely and transparently for the end user.

Having warned you, and in order to use WordPress and SQLite, the first you have to do is download the plugin from the official repository https://wordpress.org/plugins/sqlite-integration/.

Then we unzip the files and move the folder (sqlite-integration) to wp-content/plugins along with the db.php file found in sqlite-integration/db.php but this one goes to wp-content. It’s not necessary to edit the database parameters in wp-config (salt, table prefix, etc; must be modified though).

Finally, we install WordPress as usual. When the process concludes the site will be up and running using a SQLite database.

By default, the database file is located in wp-content/database/.ht.sqlite and that folder also contains a .htaccess file that denies the access using a DENY FROM ALL statement. It’s possible to change this path with an option in wp-config.php

define('DB_FILE', 'your_database_name');

define('DB_DIR', '/home/youraccount/database_directory/');

It’s possible to use a MySQL database again, but it must be taken into consideration the fact that no information will be migrated or preserved from the SQLite database, so basically, the site will start over. In order to change the engine, we add the following in wp-config.php

define('USE_MYSQL', true);

If changed back to false we use SQLite again.

Finally, despite of appearing in the plugins’ list, it’s not mandatory for it to be active to use SQLite, however, if we choose to keep it active there will be extra functions available such as an export feature that will save us the time of searching for it through ftp.

A list of incompatible plugins can be found in the author’s website http://dogwood.skr.jp/wordpress/sqlite-integration/#plugin-compat

In a next post I will talk about site migration when this engine is used.