0

There's many questions about similar issues, but none in particular about the combination of the error 500 with Django. E.g. similar questions:

Apache error log:

[Wed Jun 19 18:41:44.364270 2019] [access_compat:error] [pid 9386:tid 140669708334848] [client 1.2.3.4:1948] AH01797: client denied by server configuration: /home/user/website/wsgi.py, referer: https://website.org/admin/login/?next=/admin/

The error is shown as:

Error 500: Internal Server Error

But this only appears when trying to access admin panel, not when browsing the pages, or downloading files behind Apache protected directories. All the Q/A's I could find talk about an error in the Apache settings, but it doesn't seem to be there (nothing was changed with Apache since install).

CoderGuy123
  • 321
  • 1
  • 3
  • 11

1 Answers1

0

The error messages were misleading. The actual cause of the bug was that the server database was being served by sqlite, and the file had gotten the wrong ownership during an update. It was now owned by root and wasn't writable by the Django Apache user (www-data):

username@servername:~/project$ ls -lsa
total 924
  4 drwxr-xrwx 7 www-data www-data    4096 Mar 22 02:48 .
  4 drwxr-xrwx 4 www-data www-data    4096 Dec 24  2017 ..
880 -rwxr-xr-x 1 root     root     1046528 Mar 22 02:48 db.sqlite3
  4 drwxr-xrwx 5 www-data www-data    4096 Mar  2 12:56 files
  4 drwxr-xrwx 7 www-data www-data    4096 Mar 26 22:13 front
  4 drwxr-xrwx 8 www-data www-data    4096 Jun 11 15:24 .git
  4 -rwxrwxr-x 1 username username    1218 Nov  8  2018 .gitignore
  4 -rwxrwxrwx 1 www-data www-data     800 Apr  3  2017 manage.py
  4 drwxr-xrwx 3 www-data www-data    4096 Mar 26 15:42 project
  4 -rwxrwxrwx 1 www-data www-data      56 Jun  2  2017 README.md
  4 -rw-rw-r-- 1 username username      49 Nov  8  2018 requirements.txt
  4 drwxrwxrwx 4 www-data www-data    4096 Jan 11  2017 static

The Django admin panel updates the database upon user login into the admin panel (for record keeping), the failure to be able to do this results in a 500 error.

To fix this, just change the ownership back to normal:

sudo chown www-data: db.sqlite3
CoderGuy123
  • 321
  • 1
  • 3
  • 11