Skip to content

Instantly share code, notes, and snippets.

@GoodnessEzeokafor
Last active March 21, 2020 17:27
Show Gist options
  • Save GoodnessEzeokafor/fe49cd6ea57e5ec0c2c9961ed496b679 to your computer and use it in GitHub Desktop.
Save GoodnessEzeokafor/fe49cd6ea57e5ec0c2c9961ed496b679 to your computer and use it in GitHub Desktop.
  • Create a droplet

  • create a ssh key

  • copy the .pub and paste it

  • ssh into the project with the ip server address provided (ssh root@ip_serve)

  • after logging in create a user with root priveleges

    • adduser username

    • usermod -aG sudo username
  • sudo apt update

  • sudo apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx curl

  • log into postgresql

    • sudo -u postgres psql
    • CREATE DATABASE myproject;
    • CREATE USER myprojectuser WITH PASSWORD 'password';
    • ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
    • ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
    • ALTER ROLE myprojectuser SET timezone TO 'UTC';
  • create your virtual environment and django project

  • sudo ufw allow 8000

  • gunicorn --bind 0.0.0.0:8000 mysite.wsgi

  • gunicorn --bind 0.0.0.0:8000 mysite.wsgi

  • deactivate

  • sudo nano /etc/systemd/system/gunicorn.socket

    • [Unit] Description=gunicorn socket

    [Socket] ListenStream=/run/gunicorn.sock

    [Install] WantedBy=sockets.target

  • sudo nano /etc/systemd/system/gunicorn.service * [Unit] Description=gunicorn daemon Requires=gunicorn.socket After=network.target [Service] User=sammy Group=www-data WorkingDirectory=/home/goodness/project/src ExecStart=/home/goodness/project/myprojectenv/bin/gunicorn
    --access-logfile -
    --workers 3
    --bind unix:/run/gunicorn.sock
    mysite.wsgi:application

  • sudo systemctl start gunicorn.socket

  • sudo systemctl enable gunicorn.socket

  • sudo systemctl status gunicorn.socket

  • file /run/gunicorn.sock

  • sudo journalctl -u gunicorn.socket

  • sudo systemctl status gunicorn

  • sudo systemctl status gunicorn

  • sudo systemctl daemon-reload

  • sudo systemctl restart gunicorn

    • [Unit] Description=gunicorn daemon Requires=gunicorn.socket After=network.target

[Service] User=goodness Group=www-data WorkingDirectory=/home/goodness/Gorealla/src ExecStart=/home/goodness/Gorealla/bin/gunicorn
--access-logfile -
--workers 3
--bind unix:/run/gunicorn.sock
mysite.wsgi:application

[Install] WantedBy=multi-user.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment