SQLite and WordPress
While learning WordPress theme development, one of my biggest frustrations was setting up development environments to test different features or begin a new project.
Often times, I simply wanted to fiddle around with various features or test a layout, but setting up a local environment was tricky at the beginning. I wasn’t hip yet to virtual environments such as Vagrant and to speak honestly, I’m still not. It’s on my to-do list.
One of the great things about OSX is that it ships with PHP out of the box making spinning up a PHP server a breeze. However, getting a database server up and running was a challenge in the beginning while I was simply trying to get the basics of web development down.
After learning about the portability of SQLite, I searched for a simple solution to set it as the default database in WordPress. And, to my rescue, there was already a plug-in enabling this exact thing already floating out there.
Here is the SQLite Integration by Kojima Toshiyasu.
Although the plug-in has not been updated for some time, I’ve encountered no problems with it so far, though that does not guarantee it will remain bug-free.
I went ahead and did the work of downloading and integrating the plugin into a base install of WordPress. The instructions are not difficult if you’d like to do it yourself. I simply followed this guide here.
But to make things simple you are free to clone my repo here and get started quickly and easily in a matter of seconds.
Clone the repository:
git clone http://github.com/joemalott/sqlitepress your-project-name
Then simply move into your project directory
cd your-project-name
Then fire up PHP server. On OSX this is
php -S localhost:8000
Open a browser at http://localhost:8000 and after inputting admin credentials you are immediately in a new instance of WordPress. With the power of SQLite you now have a highly portable instance to begin tinkering with.
Please do not use this in large-scale production environments. Even small-scale projects may encounter unforeseen errors due to the use of SQLite.
This is mainly a great tool to quickly begin theme development. Coupled with the fantastic FakerPress plugin to generate some fake data, you can pretty much have a blank canvas ready to begin theming within 5 minutes.
Happy Theming. 🙂