I have just created a Django project with
python manage.py startapp smartrecruitment
I then ran a db sync
python manage.py syncdb
Operations to perform:
Apply all migrations: admin, contenttypes, auth, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying sessions.0001_initial... OK
And added my superuser, but I cannot access /admin in the browser. I have tried doing the following commands to give apache permissions, but have had no luck.
sudo chown apache <folder_containing_db.sqlite3>
sudo chown apache db.sqlite3
change owner of the project directory and database file www-data
chown www-data:www-data /home/username/Django
chown www-data:www-data /home/username/Django/db.sqlite
You have indeed user/group permission problems : you need to run your webserver with a user who has read / write access to your db file (when using sqlite3)
Changing the owner and the group of your entire project is a bad idea since it would allow your web server user to write on your codebase, which is never a good practice.
A better idea is to use a real database in production instead of sqlite to avoid this.
https://docs.djangoproject.com/en/1.9/ref/settings/#databases
If you want to stick with sqlite : place your sqlite file outside of your project repository and give it and the containing directory correct read/write accesses (for instance only www-data can write, but then you need to run your django commands as www-data)
some_dir [your_user:your_group]
--- your_django_project [github_user:github_user]
--- another_dir [www-data:www-data]
|--- db.sqlite3 [www-data:www-data]
And your webserver (apache / nginx ) runs as www-data
I was looking for the solution, as I followed CentOS tutorial by this link. https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7
Here is the permission for that tutorial,
sudo usermod -a -G root apache
chmod 710 /root/myproject
chown apache:apache /root/myproject
chown apache:apache /root/myproject/db.sqlite
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With