Skip to main content

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

django_ubuntu_deployer-4.3.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

django_ubuntu_deployer-4.3.0-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page