SQLite 3 and PHP: "unable to open database file"


2014-01-10

While playing with SQLite 3 and PHP, I encountered an oddity: the SQLite database file must be writable AND be in a writable directory. So if you're running SQLite commands from within a PHP web page, the directory your database is in and the database itself must be writable by your www user. With most GNU/Linux distros, this would take care of it:


sudo chown yourusername:www-data -R /path/to/db
sudo chmod 775 -R /path/to/db/yourdb.db

I wouldn't advise working directly in your home folder or changing its permissions/ownership, though.