Attempt to write a readonly database - Django w/ SELinux error

后端 未结 8 1849
粉色の甜心
粉色の甜心 2020-12-07 18:32

I have a CentOS server on which I have Apache, Django, Django CMS and mod_wsgi. My Django project files are stored in the /srv directory and I have SELinux tur

相关标签:
8条回答
  • 2020-12-07 19:24

    I ran into a similar issue. To check if SELinux is the problem, one can check its running status with

    sestatus
    

    and temporarily disable it with

    setenforce 0
    

    This could at least help to narrow down the problem.

    0 讨论(0)
  • 2020-12-07 19:27

    I had this issue and I solved it by creating a directory in mysite folder to hold my db.sqlite3 file. so I did /home/user/src/mysite/database/db.sqlite3. In my django setting file I change my

     DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': "/home/user/src/mysite/database/db.sqlite3" ,
    }}
    

    I did this to make Django aware that I am storing my database in a sub directory of the base directory, which mysite in my case. Now you need to grant the permission to apache to be able read write the database.

    chown user:www-data database/db.sqlite3
    chown user:www-data database 
    chmod 755 database
     chmod 755 database/db.sqlite3
    

    This solved my problem. Here is a list of the different permissions. You can use choose the one that fits you but avoid 777 and 666

    -rw------- (600) -- Only the user has read and write permissions.

    -rw-r--r-- (644) -- Only user has read and write permissions; the group and others can read only.

    -rwx------ (700) -- Only the user has read, write and execute permissions.

    -rwxr-xr-x (755) -- The user has read, write and execute permissions; the group and others can only read and execute.

    -rwx--x--x (711) -- The user has read, write and execute permissions; the group and others can only execute.

    -rw-rw-rw- (666) -- Everyone can read and write to the file. Bad idea.

    -rwxrwxrwx (777) -- Everyone can read, write and execute. Another bad idea.

    Here are a couple common settings for directories:

    drwx------ (700) -- Only the user can read, write in this directory.

    drwxr-xr-x (755) -- Everyone can read the directory, but its contents can only be changed by the user.

    here is a link to an article to [learn more][1]

    [1]: http://ftp.kh.edu.tw/Linux/Redhat/en_6.2/doc/gsg/s1-navigating-chmodnum.htm#:~:text=%2Drwxr%2Dxr%2Dx%20(,and%20others%20can%20only%20execute.

    0 讨论(0)
提交回复
热议问题