Django-hosting » History » Version 23
Nico Schottelius, 12/02/2019 11:54 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 | 14 | Nico Schottelius | |
50 | 10 | Nico Schottelius | h2. Deploy |
51 | 1 | Nico Schottelius | |
52 | 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): |
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 | 10 | Nico Schottelius | * Deploy / update your app into the folder *~app/app* (that is the app folder in the home of the user app) |
61 | 1 | Nico Schottelius | * We recommended to use git to deploy it |
62 | 11 | Nico Schottelius | |
63 | h2. Install python requirements into the pyvenv |
||
64 | |||
65 | 13 | Nico Schottelius | Pyvenv has been installed to *~app/pyvenv* for you. |
66 | Required packages for the hosting like PostgreSQL support and uwsgi support have already been placed. |
||
67 | |||
68 | You need to use pyvenv found in *~app/pyvenv*, as uwsgi loads this pyvenv before loading your app. |
||
69 | |||
70 | To install your requirements use: |
||
71 | 11 | Nico Schottelius | |
72 | <pre> |
||
73 | . ~/pyvenv/bin/activate |
||
74 | pip install ... |
||
75 | </pre> |
||
76 | 10 | Nico Schottelius | |
77 | h2. Restarting the app |
||
78 | 2 | Nico Schottelius | |
79 | * *sudo systemctl restart uwsgi* |
||
80 | |||
81 | |||
82 | 1 | Nico Schottelius | h3. Viewing logfiles |
83 | 4 | Nico Schottelius | |
84 | * nginx access log: *tail -F /var/log/nginx/access.log* |
||
85 | 7 | Nico Schottelius | * nginx error log: *tail -F /var/log/nginx/error.log* |
86 | 6 | Nico Schottelius | * uwsgi log: *tail -F /var/log/uwsgi/app/app.log* |
87 | 4 | Nico Schottelius | |
88 | 1 | Nico Schottelius | |
89 | |||
90 | h2. Description of the stack |
||
91 | |||
92 | h3. Technologies |
||
93 | |||
94 | 22 | Nico Schottelius | * Debian |
95 | 1 | Nico Schottelius | * nginx |
96 | * PostgreSQL |
||
97 | 3 | Nico Schottelius | * uwsgi |
98 | 20 | Nico Schottelius | * pyvenv |
99 | 3 | Nico Schottelius | |
100 | h3. Configuration |
||
101 | |||
102 | * user "app" |
||
103 | ** in group "adm" (to view logfiles) |
||
104 | * PostgreSQL with |
||
105 | 1 | Nico Schottelius | ** database "app" |
106 | 3 | Nico Schottelius | ** Listens only on localhost / socket (no remote connections) |