Skip to content

Instantly share code, notes, and snippets.

@0xKD
Created April 17, 2021 15:43
Show Gist options
  • Save 0xKD/fe56d13e2dca27c0b26a3fe6c84597ab to your computer and use it in GitHub Desktop.
Save 0xKD/fe56d13e2dca27c0b26a3fe6c84597ab to your computer and use it in GitHub Desktop.
Single server deployment

Single server deployment

  • Create new user
adduser <username>
usermod -aG sudo <username>  # enable sudo
  • Setup passwordless sudo
EDITOR=vim visudo
# add below line
# <username> ALL=(ALL) NOPASSWD: ALL
  • Download caddy-server (for https)
  • ssh-keygen for code download
  • Install pyenv & pyenv-virtualenv
# pyenv
sudo apt install curl git-core gcc make zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libssl-dev -y
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# try ~/.bashrc if ~/.bash_profile doesn't work
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

# pyenv-virtualenv
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
  • Setup virtualenv using pyenv
pyenv install 3.6.13
pyenv virtualenv 3.6.13 my-venv
  • Gunicorn server
# from manage.py directory
gunicorn project.wsgi
  • Caddy reverse-proxy
# this will attempt auto-https using Lets Encrypt
./caddy reverse-proxy --from=sub.domain.com --to=127.0.0.1:8000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment