Using SQLite with PHP on Heroku

Last reviewed on January 24, 2020

1. Our Project

Let's say we have a project with the following directory structure:

  • index.php
  • database.sqlite

Our index.php file contains the following:

$pdo = new PDO('sqlite:database.sqlite');
// ... the rest of your code

2. Run Composer

First, create the file composer.json in the root of the project with the following contents:

{
  "require": {
    "ext-pdo_sqlite": "*"
  }
}

This will enable the pdo_sqlite PHP extension on Heroku. You can read more about how to enable various PHP extensions on Heroku here.

Next, install Composer and run composer install. This will generate a composer.lock file. Add vendor to your .gitignore.

3. Deploy to Heroku

The app is good to go! Just push up these changes to Heroku and everything should work.