Rails: SQLite3::CantOpenException: unable to open database file Rails: SQLite3::CantOpenException: unable to open database file sqlite sqlite

Rails: SQLite3::CantOpenException: unable to open database file


SQLLite works by having the Rails process write to a system file within the Rails directory tree. The Rails process is owned by Apache, which sets a user "apache" and a group "apache" by default. To make it work you would need to give write permissions to the apache user or group on the /db directory.

OR

Configure apache to run with a group already having write permissions to the directory. A good strategy is to create a group of the various processes that may need access to various locations -- for example I have a "deployer" group that the user doing releases would be part of, along with the apache instance. I typically find that having a group that the various process and login users are part of makes life easier (e.g. for looking at server logs), writing uploads or cached files, etc.

AND/OR

Use a real database server like PostgreSQL or MySQL -- they work because they are their own processes that manage their own files. The Rails process (apache, in your case) connects to the database server process on a Unix port. Each server process securely manages only files it knows about.

SQLLite is fine to get started -- super easy and low overhead, but very soon you'll need to run a regular database server on production. And then you'll soon find that things aren't exactly the same between SQLLite and the others, at which point you should just install the same database server on your dev machine.


It's because nginx create www-data user, and this user don't have a previlegues to read sqlite3 file and your app...

You need to run commands:

1.sudo chown -R www-data:www-data rails_project/

2.sudo chmod -R 777 rails_project/

And check that you kick off your app in production mode.


Ran into this issue in an app where everything is owned by root.

Here is how i got solved.

root@se785fall16:/var/www/auth_whateveryousay# chmod -R 0777 db/root@se785fall16:/var/www/auth_whateveryousay# ls -lad *drwxr-xr-x 11 root root  4096 Nov 27 17:23 appdrwxr-xr-x  2 root root  4096 Nov 27 17:23 bindrwxr-xr-x  5 root root  4096 Nov 27 17:23 config-rw-r--r--  1 root root   130 Nov 27 17:23 config.rudrwxrwxrwx  3 root root  4096 Nov 27 17:33 db-rw-r--r--  1 root root   879 Nov 27 17:23 Gemfile-rw-r--r--  1 root root  6367 Nov 27 17:24 Gemfile.lockdrwxr-xr-x  4 root root  4096 Nov 27 17:23 libdrwxr-xr-x  2 root root  4096 Nov 27 17:25 logdrwxr-xr-x  2 root root  4096 Nov 27 17:23 public-rw-r--r--  1 root root   227 Nov 27 17:23 Rakefile-rw-r--r--  1 root root   898 Nov 27 17:23 README-rw-r--r--  1 root root 26632 Nov 27 17:23 README.textiledrwxr-xr-x  6 root root  4096 Nov 27 17:23 specdrwxrwxrwx  5 root root  4096 Nov 27 17:25 tmpdrwxr-xr-x  3 root root  4096 Nov 27 17:23 vendor

Bottom line is : this is premssions issue and you will need to make sure that whoever owns the app wether it be root or non-root, you will just need to give that user read and write access on the database being used chmod -R 0777 db/. Tweak this to fit your own security level.