Simple way to deploy Django app in Ubuntu Server.
Project description
Django Ubuntu Deployer
This is a simple package for deploying django projects on ubuntu server 16.04 or latest.
Does what is written in article How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 16.04 | DigitalOcean.
In Ubuntu Server
ubuntu@server:~# cd /home/
ubuntu@server:/home# sudo apt-get update
ubuntu@server:/home# sudo apt-get install python3-pip python3-dev libpq-dev nginx
Install virtualenv for creating virtual environment:
ubuntu@server:/home# pip3 install virtualenv
Create project folder and enter in:
ubuntu@server:/home# mkdir project && cd project
Create virtual environment and activate:
ubuntu@server:/home/project# virtualenv venv
ubuntu@server:/home/project# source venv/bin/activate
Install Django, django_ubuntu_deployer and gunicorn
(venv)ubuntu@server:/home/project# pip install django django_ubuntu_deployer gunicorn
Register django_ubuntu_deployer in INSTALLED_APPS
INSTALLED_APPS = [
...,
'ubuntu_deployer',
]
Add domains to ALLOWED_HOSTS:
ALLOWED_HOSTS = [
'your domain 1',
...,
'your domain n',
]
Collectstatic files:
(venv)ubuntu@server:/home/project# python manage.py collectstatic
Now deploy your APP in Ubuntu Server (use for this username and password):
(venv)ubuntu@server:/home/project# python manage.py deploy
Or restart server
(venv)ubuntu@server:/home/project# python manage.py deploy --restart
Configure gunicorn, nginx and virtual environment folder
In your settings.py:
DJANGO_UBUNTU_DEPLOYER = {
# gunicorn config
# required in gunicorn config {user}, {path}, {gunicorn}, {sock}, {name}
'GUNICORN_CONFIG': """
Description=gunicorn daemon
After=network.target
[Service]
User={user}
Group=www-data
WorkingDirectory={path}
ExecStart={gunicorn} --access-logfile - --workers 3 --bind unix:{sock} {name}.wsgi:application
[Install]
WantedBy=multi-user.target
""",
# nginx config
# required in nginx config {domains}, {static}, {media}, {path}, {sock}, {extras}
'NGINX_CONFIG': """
server {{
listen 80;
server_name {domains};
location = /favicon.ico {{ access_log off; log_not_found off; }}
location {static} {{
root {path};
}}
location {media} {{
root {path};
}}
location / {{
include proxy_params;
proxy_pass http://unix:{sock};
}}
{extras}
}}
""",
# nginx_config extras
'NGINX_EXTRAS': '',
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_ubuntu_deployer-4.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce3ce12ed7a5ea6256b707af0df5742e122f3c0a5410af5d4b667e6f0d959cc4 |
|
MD5 | 318ae8989641cc3b20b473dac8d6342c |
|
BLAKE2b-256 | 344a14a635c250174404f3d4c6885daafd30250c99bbd266c0b697c01db44fba |
Close
Hashes for django_ubuntu_deployer-4.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27314e1d885c0cdcfe08e0f963d9501bcf1d83255b073e75d1f8d8d476cb7746 |
|
MD5 | 60580195577267eb1e905308d528cfad |
|
BLAKE2b-256 | 8ac689c8220838cad4b833894578e20be244cfc802a503a86823770ecfcb8554 |