Project

General

Profile

Django-hosting » History » Version 26

Nico Schottelius, 09/01/2020 10:58 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 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 24 Nico Schottelius
h2. Deploy (first time)
51 1 Nico Schottelius
52 25 Nico Schottelius
You can login to your VM as user *app*:
53 1 Nico Schottelius
54 10 Nico Schottelius
<pre>
55
ssh app@MYHOSTNAME
56 17 Nico Schottelius
git clone <path-to-your-project> ~/app
57 10 Nico Schottelius
</pre>
58 4 Nico Schottelius
59 1 Nico Schottelius
60
* Deploy / update your app into the folder *~app/app* (that is the app folder in the home of the user app)
61
* We recommended to use git to deploy it
62 24 Nico Schottelius
63
h2. Deploy (update)
64
65
<pre>
66
ssh app@MYHOSTNAME
67
cd ~/app
68
git pull
69
</pre>
70
71 11 Nico Schottelius
72
h2. Install python requirements into the pyvenv
73
74 13 Nico Schottelius
Pyvenv has been installed to *~app/pyvenv* for you.
75
Required packages for the hosting like PostgreSQL support and uwsgi support have already been placed.
76
77
You need to use pyvenv found in *~app/pyvenv*, as uwsgi loads this pyvenv before loading your app.
78
79
To install your requirements use:
80 11 Nico Schottelius
81
<pre>
82
. ~/pyvenv/bin/activate
83
pip install ...
84
</pre>
85 10 Nico Schottelius
86
h2. Restarting the app
87 2 Nico Schottelius
88
* *sudo systemctl restart uwsgi*
89
90
91 1 Nico Schottelius
h3. Viewing logfiles
92 4 Nico Schottelius
93
* nginx access log: *tail -F /var/log/nginx/access.log*
94 7 Nico Schottelius
* nginx error log: *tail -F /var/log/nginx/error.log*
95 6 Nico Schottelius
* uwsgi log: *tail -F /var/log/uwsgi/app/app.log*
96 4 Nico Schottelius
97 1 Nico Schottelius
98
99
h2. Description of the stack
100
101
h3. Technologies
102
103 22 Nico Schottelius
* Debian
104 1 Nico Schottelius
* nginx
105
* PostgreSQL
106 3 Nico Schottelius
* uwsgi
107 20 Nico Schottelius
* pyvenv
108 3 Nico Schottelius
109
h3. Configuration
110
111
* user "app"
112
** in group "adm" (to view logfiles)
113
* PostgreSQL with
114 1 Nico Schottelius
** database "app"
115 3 Nico Schottelius
** Listens only on localhost / socket (no remote connections)