Project

General

Profile

Django-hosting » History » Version 28

Nico Schottelius, 11/05/2020 05:30 PM

1 23 Nico Schottelius
h1. Django hosting by ungleich
2 1 Nico Schottelius
3 9 Nico Schottelius
{{toc}}
4 1 Nico Schottelius
5 22 Nico Schottelius
h2. Status
6
7 26 Nico Schottelius
This document is **IN PRODUCTION** (since 2016-04-08). 
8
Pricing can be found on the "ungleich products page":https://ungleich.ch/u/products/django-hosting/.
9 22 Nico Schottelius
10 1 Nico Schottelius
h2. How to use
11
12 8 Nico Schottelius
# Configure your app
13
# Deploy your app
14 18 Nico Schottelius
# Install project specific python requirements into the pyvenv
15 8 Nico Schottelius
# Restart uwsgi to restart your app
16
# Go to http://your-hostname/ and enjoy!
17 1 Nico Schottelius
18
19 8 Nico Schottelius
h2. Configure your app
20
21
h3. WSGI
22
23
* Ensure that there is _projectname_/wsgi.py in your project root
24
25
h3. Database
26
27
Add the following to your settings.py:
28
29
<pre>
30
DATABASES = {
31
    'default': {
32
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
33
        'NAME': 'app',
34
    }
35
}
36 4 Nico Schottelius
</pre>
37 14 Nico Schottelius
38 1 Nico Schottelius
h3. Static and media files
39 14 Nico Schottelius
40 22 Nico Schottelius
Static files should be placed in */home/app/app/static* and media files in */home/app/app/media*.
41 14 Nico Schottelius
42 16 Nico Schottelius
Use the following code for configuration:
43
44
<pre>
45 21 Nico Schottelius
PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
46 16 Nico Schottelius
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
47
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
48
</pre>
49
50 27 Nico Schottelius
Usually to generate/deploy the static files, you can use collectstatic:
51
52
<pre>
53
python manage.py collectstatic                                                             </pre>
54
55
56 24 Nico Schottelius
h2. Deploy (first time)
57 1 Nico Schottelius
58 25 Nico Schottelius
You can login to your VM as user *app*:
59 1 Nico Schottelius
60 10 Nico Schottelius
<pre>
61
ssh app@MYHOSTNAME
62 17 Nico Schottelius
git clone <path-to-your-project> ~/app
63 10 Nico Schottelius
</pre>
64 4 Nico Schottelius
65 1 Nico Schottelius
66
* Deploy / update your app into the folder *~app/app* (that is the app folder in the home of the user app)
67
* We recommended to use git to deploy it
68 24 Nico Schottelius
69
h2. Deploy (update)
70
71
<pre>
72
ssh app@MYHOSTNAME
73
cd ~/app
74
git pull
75
</pre>
76
77 11 Nico Schottelius
78
h2. Install python requirements into the pyvenv
79
80 13 Nico Schottelius
Pyvenv has been installed to *~app/pyvenv* for you.
81
Required packages for the hosting like PostgreSQL support and uwsgi support have already been placed.
82
83
You need to use pyvenv found in *~app/pyvenv*, as uwsgi loads this pyvenv before loading your app.
84
85
To install your requirements use:
86 11 Nico Schottelius
87
<pre>
88
. ~/pyvenv/bin/activate
89
pip install ...
90
</pre>
91 10 Nico Schottelius
92
h2. Restarting the app
93 2 Nico Schottelius
94
* *sudo systemctl restart uwsgi*
95
96
97 1 Nico Schottelius
h3. Viewing logfiles
98 4 Nico Schottelius
99
* nginx access log: *tail -F /var/log/nginx/access.log*
100 7 Nico Schottelius
* nginx error log: *tail -F /var/log/nginx/error.log*
101 6 Nico Schottelius
* uwsgi log: *tail -F /var/log/uwsgi/app/app.log*
102 4 Nico Schottelius
103 1 Nico Schottelius
104
105
h2. Description of the stack
106
107
h3. Technologies
108
109 22 Nico Schottelius
* Debian
110 1 Nico Schottelius
* nginx
111
* PostgreSQL
112 3 Nico Schottelius
* uwsgi
113 28 Nico Schottelius
* python3 venv
114 3 Nico Schottelius
115
h3. Configuration
116
117
* user "app"
118
** in group "adm" (to view logfiles)
119
* PostgreSQL with
120 1 Nico Schottelius
** database "app"
121 3 Nico Schottelius
** Listens only on localhost / socket (no remote connections)