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