2

I am trying to get writing privileges to my sqlite3.db file in my django project hosted on bluehost, but I cannot get any other chmod command to work besides the dangerous/risky chmod 777. When I chmod 777 the db file and the directory, everything works perfectly.

However, in order to be more prudent, I’ve tried chmodding 775 the directory of the sqlite file and chmod 664 the actual db file itself. No luck. I still get OperationalError: Attempt to Write to a Read Only Database whenever I access a feature that requires writing to the db.

I appreciate any assistance.

4
  • You may need to change the ownership (the chown command) of the files to a different user. Commented Dec 21, 2014 at 23:10
  • Is there a specific user that I need to change to? By default, it's apache correct? Commented Dec 21, 2014 at 23:13
  • On my site (codypiersall.com -- you should visit it, it's good for a quick laugh), which is hosted by A Small Orange, the owner is codypier, which is my user account. When it comes to administering servers I'm not great, though. Commented Dec 21, 2014 at 23:15
  • Haha that's a sick website :P I'll try changing the user to root then and seeing what I can do. Commented Dec 21, 2014 at 23:30

1 Answer 1

1

The user accessing the database (www-data?) needs to have write privileges to the folder the data resides in as well as the file itself. I would probably change the group ownership (chgrp) of the folder to www-data and add a group sticky bit to the folder as well (chmod g+s dbfolder). The last one makes sure that any new files created belongs to the group owner.

If you're on bluehost you should also have access to MySql (which is a much better choice for web-facing db).

Sign up to request clarification or add additional context in comments.

4 Comments

So anyone accessing the database from the internet will be treated as user www-data if I understood you correctly? So basically I have to change the directory owner to www-data by doing chown www-data /home/dbdirectory Is that correct?
If you're using Django, you're running under a webserver. Apache normally/frequently runs as user www-data (but this can vary by installation and configuration). Whenever a request comes in, the webserver runs to service it, and it is the user that the webserver runs as that needs access. Files and directories in linux have an owner and a group owner, and access can be granted based on either. To change the owner you would use chown newuser file-or-dir to change the group-owner you would use chgrp newgroup file-or-dir and to change both you would use chown newuser:newgroup file-or-dir.
Excellent. Thanks. I understand what I'm supposed to do. However, when I try to change owner to www-data, it tells me that user or group does not exist. So I'm guessing that is not the correct name for the user under my installation/configuration of apache. Is there a way I can check what user the webserver is running as? Thanks for your help so far.
ps aux | egrep '(apache|httpd)' should give you an idea of which user it is.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.