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