Django-hosting » History » Revision 24

Revision 23 (Nico Schottelius, 12/02/2019 11:54 AM) → Revision 24/28 (Nico Schottelius, 01/15/2020 11:24 AM)

h1. Django hosting by ungleich 


 h2. Status 

 This document is **IN PRODUCTION** (since 2016-04-08) 

 h2. How to use 

 # Configure your app 
 # Deploy your app 
 # Install project specific python requirements into the pyvenv 
 # Restart uwsgi to restart your app 
 # Go to http://your-hostname/ and enjoy! 

 h2. Configure your app 

 h3. WSGI 

 * Ensure that there is _projectname_/ in your project root 

 h3. Database 

 Add the following to your 

     'default': { 
         'ENGINE': 'django.db.backends.postgresql_psycopg2', 
         'NAME': 'app', 

 h3. Static and media files 

 Static files should be placed in */home/app/app/static* and media files in */home/app/app/media*. 

 Use the following code for configuration: 

 PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) 
 STATIC_ROOT = os.path.join(BASE_DIR, "static/") 
 MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media') 


 h2. Deploy (first time) 

 You can login to your VM as user *app* (for the django app) and *root* (in case you need to change settings): 

 ssh app@MYHOSTNAME 
 git clone <path-to-your-project> ~/app 

 * Deploy / update your app into the folder *~app/app* (that is the app folder in the home of the user app) 
 * We recommended to use git to deploy it 

 h2. Deploy (update) 

 ssh app@MYHOSTNAME 
 cd ~/app 
 git pull 

 h2. Install python requirements into the pyvenv 

 Pyvenv has been installed to *~app/pyvenv* for you. 
 Required packages for the hosting like PostgreSQL support and uwsgi support have already been placed. 

 You need to use pyvenv found in *~app/pyvenv*, as uwsgi loads this pyvenv before loading your app. 

 To install your requirements use: 

 . ~/pyvenv/bin/activate 
 pip install ... 

 h2. Restarting the app 

 * *sudo systemctl restart uwsgi* 

 h3. Viewing logfiles 

 * nginx access log: *tail -F /var/log/nginx/access.log* 
 * nginx error log: *tail -F /var/log/nginx/error.log* 
 * uwsgi log: *tail -F /var/log/uwsgi/app/app.log* 

 h2. Description of the stack 

 h3. Technologies 

 * Debian 
 * nginx 
 * PostgreSQL 
 * uwsgi 
 * pyvenv 

 h3. Configuration 

 * user "app" 
 ** in group "adm" (to view logfiles) 
 * PostgreSQL with 
 ** database "app" 
 ** Listens only on localhost / socket (no remote connections)