Project

General

Profile

Django-hosting » History » Version 24

Nico Schottelius, 01/15/2020 11:24 AM

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