PDO SQlite error: unable to open database file

When you're testing your PHP applications with SQLite you might bump into a problem when using PDOthat states "SQLSTATE[HY000]: General error: 14 unable to open database file".
When using Zend Framework 2, you might only get the InvalidQueryException "Statement could not be executed", for which I've made a pull request on Github to make it more clear what's going on.
The problem is about permissions. For SQLite it's not enough to make the database file writeable for the web server user, but also the directory this file is in.
I found the solution on StackOverflow, thanks to Austin Hyde for giving the answer that pointed me in the final path to the solution.
In order to fix this issue I changed the group of the directory and db file to "www-data", the group my web server (Apache) was running on, and made them writeable for the group.
$ cd /path/to/application
$ chgrp www-data data/db
$ chgrp www-data data/db/application-test.db
$ chmod g+w data/db
$ chmod g+w data/db/application-test.db
Hope to help other developers using SQLite in their development save a lot of time searching for something this trivial.


  1. Anonymous14/8/17 02:13

    Thanks a lot man!

    That helped me fixing the same issue in my lumen apllication.


Post a Comment

Popular Posts