Django-hosting » History » Version 19
Nico Schottelius, 04/08/2016 01:19 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 | STATIC_ROOT = os.path.join(BASE_DIR, "static/") |
||
41 | MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media') |
||
42 | </pre> |
||
43 | |||
44 | 14 | Nico Schottelius | |
45 | 10 | Nico Schottelius | h2. Deploy |
46 | 1 | Nico Schottelius | |
47 | 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): |
48 | 1 | Nico Schottelius | |
49 | 10 | Nico Schottelius | <pre> |
50 | ssh app@MYHOSTNAME |
||
51 | 17 | Nico Schottelius | git clone <path-to-your-project> ~/app |
52 | 10 | Nico Schottelius | </pre> |
53 | 4 | Nico Schottelius | |
54 | 1 | Nico Schottelius | |
55 | 10 | Nico Schottelius | * Deploy / update your app into the folder *~app/app* (that is the app folder in the home of the user app) |
56 | 1 | Nico Schottelius | * We recommended to use git to deploy it |
57 | 11 | Nico Schottelius | |
58 | h2. Install python requirements into the pyvenv |
||
59 | |||
60 | 13 | Nico Schottelius | Pyvenv has been installed to *~app/pyvenv* for you. |
61 | Required packages for the hosting like PostgreSQL support and uwsgi support have already been placed. |
||
62 | |||
63 | You need to use pyvenv found in *~app/pyvenv*, as uwsgi loads this pyvenv before loading your app. |
||
64 | |||
65 | To install your requirements use: |
||
66 | 11 | Nico Schottelius | |
67 | <pre> |
||
68 | . ~/pyvenv/bin/activate |
||
69 | pip install ... |
||
70 | </pre> |
||
71 | 10 | Nico Schottelius | |
72 | h2. Restarting the app |
||
73 | 2 | Nico Schottelius | |
74 | * *sudo systemctl restart uwsgi* |
||
75 | |||
76 | |||
77 | 1 | Nico Schottelius | h3. Viewing logfiles |
78 | 4 | Nico Schottelius | |
79 | * nginx access log: *tail -F /var/log/nginx/access.log* |
||
80 | 7 | Nico Schottelius | * nginx error log: *tail -F /var/log/nginx/error.log* |
81 | 6 | Nico Schottelius | * uwsgi log: *tail -F /var/log/uwsgi/app/app.log* |
82 | 4 | Nico Schottelius | |
83 | 1 | Nico Schottelius | |
84 | |||
85 | h2. Description of the stack |
||
86 | |||
87 | h3. Technologies |
||
88 | |||
89 | * Debian 8 |
||
90 | * nginx |
||
91 | * PostgreSQL |
||
92 | 3 | Nico Schottelius | * uwsgi |
93 | |||
94 | h3. Configuration |
||
95 | |||
96 | * user "app" |
||
97 | ** in group "adm" (to view logfiles) |
||
98 | * PostgreSQL with |
||
99 | 1 | Nico Schottelius | ** database "app" |
100 | 3 | Nico Schottelius | ** Listens only on localhost / socket (no remote connections) |