how to tell apache to see my projects database file?

27 views
Skip to first unread message

doniyor

unread,
May 29, 2012, 10:56:39 AM5/29/12
to django...@googlegroups.com
hey guys, i need your help again, 

after successful deployment, i wanted to do something with database but it says: 
DatabaseError at /ajax/
unable to open database file
because ajax is trying to write something to db. what can be the problem. in my settings.py the path is this: 

PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
...
'NAME': os.path.join(PROJECT_PATH, 'stahlbank.db'),

i am using sqlite. OS is linux. 

thanks 

Rafael Durán Castañeda

unread,
May 29, 2012, 11:57:03 AM5/29/12
to django...@googlegroups.com
El 29/05/12 16:56, doniyor escribió:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/qkkO9dd9C7AJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
I think it's just a permissions problem, did you check the user is running apache has access to the database file? Anyway, it would easier help you with a full traceback.

HTH

doniyor

unread,
May 29, 2012, 1:07:07 PM5/29/12
to django...@googlegroups.com
i did 'top', and then " ps aux | grep apache " to see. the root is running the apache. what should i do now? chown root folder/dbfile   , right  ? 


Am Dienstag, 29. Mai 2012 17:57:03 UTC+2 schrieb Rafael Durán Castañeda:
El 29/05/12 16:56, doniyor escribió:
hey guys, i need your help again, 

after successful deployment, i wanted to do something with database but it says: 
DatabaseError at /ajax/
unable to open database file
because ajax is trying to write something to db. what can be the problem. in my settings.py the path is this: 

PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
...
'NAME': os.path.join(PROJECT_PATH, 'stahlbank.db'),

i am using sqlite. OS is linux. 

thanks 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/qkkO9dd9C7AJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Rafael Durán Castañeda

unread,
May 29, 2012, 3:59:53 PM5/29/12
to django...@googlegroups.com
El 29/05/12 19:07, doniyor escribió:
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/wfrNRrc9rSoJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
If you change the Apache user or chown your files is up to you, but Apache it's not recommended (I think even it's not possible, I'm not an Apache expert) running as root due to security holes. If you look again your ps you probably will see something like this:

root     29833     1  0 May14 ?        00:00:46   /usr/sbin/apache2 -k start
www-data 15726 29833  0 May27 ?        00:00:00     /usr/sbin/apache2 -k start
www-data 15781 29833  0 May27 ?        00:00:04     /usr/sbin/apache2 -k start
www-data 15782 29833  0 May27 ?        00:00:04     /usr/sbin/apache2 -k start

where the www-data user is running your web application.

doniyor

unread,
May 29, 2012, 4:38:28 PM5/29/12
to django...@googlegroups.com
hey thanks, but i still dont get the whole mass. look, i chown all folders untill db file to root. nothing changed, the same error. i did ls -l but i dont see any user named 'www-data', i see the user that i created as superuser when i created the django project. how can i add this superuser to apache user group or something like this. i am actually not a linux guru, so i am really stuck here.. 
 
If you change the Apache user or chown your files is up to you, but Apache it's not recommended (I think even it's not possible, I'm not an Apache expert) running as root due to security holes. If you look again your ps you probably will see something like this:

Rafael Durán Castañeda

unread,
May 29, 2012, 5:17:19 PM5/29/12
to django...@googlegroups.com
El 29/05/12 22:38, doniyor escribió:
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/zfL0OoG14rcJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
I think I might help you better live (note as I said I'm not an Apache expert), you can find me (rafaduran) at #django IRC channel, among a lot of more people that probably can help you much better than me.

doniyor

unread,
May 30, 2012, 1:45:46 AM5/30/12
to django...@googlegroups.com
my browser isnot openning irc url, i dont know why. 

thing is, root is running the apache. it means, i should chown root to all my files right? 
I think I might help you better live (note as I said I'm not an Apache expert), you can find me (rafaduran) at #django IRC channel, among a lot of more people that probably can help you much better than me.

kenneth gonsalves

unread,
May 30, 2012, 1:58:41 AM5/30/12
to django...@googlegroups.com
On Tue, 2012-05-29 at 22:45 -0700, doniyor wrote:
> my browser isnot openning irc url, i dont know why.
>
> thing is, root is running the apache. it means, i should chown root to
> all
> my files right?

wrong - www-data is running apache, so you should give www-data write
access to the db.
--
regards
Kenneth Gonsalves

doniyor

unread,
May 30, 2012, 2:06:32 AM5/30/12
to django...@googlegroups.com
now i did 'sudo chgrp www-data . dbfile' but it says: invalid group www-data. do i have to create it first? 

kenneth gonsalves

unread,
May 30, 2012, 2:17:37 AM5/30/12
to django...@googlegroups.com
On Tue, 2012-05-29 at 23:06 -0700, doniyor wrote:
> now i did 'sudo chgrp www-data . dbfile' but it says: invalid group
> www-data. do i have to create it first?

www-data is a user, not a group
--
regards
Kenneth Gonsalves

doniyor

unread,
May 30, 2012, 2:24:31 AM5/30/12
to django...@googlegroups.com
if i do 'sudo chown www-data dbfile'  it says, the access is not permitted to db file.. 

doniyor

unread,
May 30, 2012, 2:29:20 AM5/30/12
to django...@googlegroups.com
okay, now it said nothing, the command went well. but the page is still showing me error: unable to open database file. 

kenneth gonsalves

unread,
May 30, 2012, 3:00:49 AM5/30/12
to django...@googlegroups.com
On Tue, 2012-05-29 at 23:29 -0700, doniyor wrote:
> okay, now it said nothing, the command went well. but the page is
> still
> showing me error: unable to open database file.

you need to chown -R
www-data:www-data /directory_in_which_the_dbfile_is/
--
regards
Kenneth Gonsalves

doniyor

unread,
May 30, 2012, 3:37:43 AM5/30/12
to django...@googlegroups.com
it says, invalid group www-data. but look, i am logged in as root with 'su'. and i am doing all the commands here. is it correct, or should i be a normal user? this doesnot make big difference right? 

kenneth gonsalves

unread,
May 30, 2012, 3:49:33 AM5/30/12
to django...@googlegroups.com
On Wed, 2012-05-30 at 00:37 -0700, doniyor wrote:
> it says, invalid group www-data. but look, i am logged in as root
> with
> 'su'. and i am doing all the commands here. is it correct, or should i
> be a
> normal user? this doesnot make big difference right?

in that case there is no need to use sudo. Try:
chown -R www-data /directory_in_which_the_dbfile_is/
--
regards
Kenneth Gonsalves

doniyor

unread,
May 30, 2012, 4:11:36 AM5/30/12
to django...@googlegroups.com
hey man, problem solved. i did chown www-data. .  then chmod 777 dbfile now everything is working fine. thank you so much for your time and help. 

r u from europe? 

kenneth gonsalves

unread,
May 30, 2012, 6:06:55 AM5/30/12
to django...@googlegroups.com
On Wed, 2012-05-30 at 01:11 -0700, doniyor wrote:
> hey man, problem solved. i did *chown www-data. . *then *chmod 777
> dbfile *now
> everything is working fine. thank you so much for your time and help.
>
> r u from europe?

no
--
regards
Kenneth Gonsalves

Thomas Lockhart

unread,
May 30, 2012, 8:29:14 AM5/30/12
to doniyor, django...@googlegroups.com
On 5/30/12 1:11 AM, doniyor wrote:
hey man, problem solved. i did chown www-data. .  then chmod 777 dbfile now everything is working fine. thank you so much for your time and help. 
I've lost track of the early parts of this thread, but chmod 777 on a database rarely indicates that everything is fine. The chown did not matter much once you gave everyone in the universe write access to the database.

This issue started as a permissions problem and still is a permissions problem. Figure out which user is actually accessing your database and get the permissions you need.

hth

                               - Tom

doniyor

unread,
May 30, 2012, 10:04:26 AM5/30/12
to django...@googlegroups.com, doniyor
what do you mean? should i do better chmod 755 which is more secure than 777?

Thomas Lockhart

unread,
May 30, 2012, 12:06:08 PM5/30/12
to django...@googlegroups.com, doniyor
On 12-05-30 7:04 AM, doniyor wrote:
what do you mean? should i do better chmod 755 which is more secure than 777?
You can do whatever you want. But the advice from the list is to figure out what account is actually accessing the database and keep the permissions on the DB the way they should be. That may be different for different databases.

So you have two things to figure out:
1) What is the effective user for your database accesses?
2) What permissions should be set on the database directories and files?

hth

                - Tom


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/UOlT738Mi6gJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages