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