Using my Django app, I'm able to read from the database just fine. When the application didn't have permission to access the file, it gave me this error:
attempt to write a readonly database
Which made sense. So I edited the permissions on the file, so that the Apache process had write permissions. However, instead of it being able to write, I get this cryptic error:
unable to open database file
If it's useful, here's the entire output:
Request Method: POST
Request URL: http://home-sv-1/hellodjango1/polls/1/vote/
Exception Type: OperationalError
Exception Value:
unable to open database file
Exception Location: /usr/lib/pymodules/python2.5/django/db/backends/sqlite3/base.py in execute, line 193
Python Executable: /usr/bin/python
Python Version: 2.5.2
Python Path: ['/var/www', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/pymodules/python2.5', '/usr/lib/pymodules/python2.5/gtk-2.0']
Server time: Sun, 23 Aug 2009 07:06:08 -0500
Let me know if a stack trace is necessary.
Aha, just stumbled across an article explaining this. Also Django have info on their NewbieMistakes page.
The solution is to make sure the directory containing the database file also has write access allowed to the process.
In my case, running this command fixed the problem:
From the Django says "Unable to Open Database File" when using SQLite3 section of the Newbie mistakes Django wiki page:
db
directory exists/tmp
directory is world-writablesettings.py
is a full pathMy solution to this was more like so. I didn't really want to change the ownership of this dir. (mostly because i use the pi user to do things like git)
(or whatever db you are using)
where pi is the user that i created all the files in. (yes this is a raspberry pi)
Instead of changing of permissions to www-data, i found that I only needed to change the permissions like this:
This gives group write access to the necessary files and adds the www-data user to the pi group.
Note: if you have logging, you will need to do this for the django logfile as well or apache won't like it much.
Adding an operational user to the www-data group is working well on my test environment. Additionally I've put the sqlite3.db file into a separate subfolder, to be more secure.
Database file shall be owned by www-data
My operational user hape gets a member of www-data group:
Allow database file write access to members of group www-data:
As a result, the database can be accessed read+write by apache2-daemon (user www-data), without giving grant to the project root folder, and - on the other hand - the app can be run in dev mode by the operational user hape, e.g.
also.
For Windows 7, 8.1, 10, Server 2012, etc. follow the Bonobo installation directions:
Allow IIS User to modify C:\inetpub\wwwroot\Bonobo.Git.Server\App_Data folder.
To do so:
Borrowed from SO question: https://stackoverflow.com/questions/4283132/apache-instance-user-permission-issue
Assuming files are owned by apache user to start:
set
ACLs
for user/group pi:You can tell there's an
ACL
withls -l
, the trailing '+' on the permissions bits:The development server needs to be run as the same user who has write perms on the database folder, so if you originally created the database as root, you will need to be root when you run:
create a subdirectory in the working directory
create sqlite database in the subdiretory
change owner for the subdirectory to www-data in debain or apache in centOS
and grab a cold beer coz your are done.
P/S: to check if the procedure was succesful
you should see such
just write
sudo sqlite3 databaseFilename.sql
and it's work