Deploy Dango blog to Vultr

vultr django

Worth experiencing the long way

1. ​ Change settings…Separate development environment settings and product environment settings

Create “local_settings.py” in your project folder where settings.py sits.

Delete “DEBUG” “SECRETE_KEY” and “ALLOWED HOSTS” from settings.py

Write “DEBUG = True” “SECRET_KEY” on local_settings.py

2. VULTR registration…

  • Add SSH key,
  • Firewall settings,
  • Deploy new instance,

3. SSH login…

  1. Add user, Update Ubuntu (sudo apt update/ sudo apt upgrade),
  2. Install (sudo apt install nginx python3-pip python3-venv),
  3. Make a folder (mkdir src),
  4. Remote-SSH: Connect to Host – Add new SSH host

Reference: https://www.vultr.com/docs/how-to-access-your-vultr-vps#SSH__Linux_

4. GitHub + Visual Studio Code

  1. Copy CODE,
  2. cd src: git clone <git CODE url>,
  3. Open copied folder on VSC,
  4. Virtual env (python3 -m venv myvenv),
  5. Activate env (source myvenv/bin/activate)

Visit Github: https://github.com/

5. Deploy…

  1. Update (pip3 install –upgrade pip setuptools),
  2. Install requirements (pip3 install -r requirements.txt): local and myvenv,
  3. Make a directory for static (sudo mkdir /usr/share/nginx/html/static),
  4. Make a directory for media (sudo mkdir /usr/share/nginx/html/media),
  5. Make .env file for environment variable (write: SECRET_KEY=xxxxx/ ALLOWED_HOSTS=127.0.0.1),
  6. Migrate (python3 manage.py migrate),
  7. Collectstatic (sudo python3 manage.py collectstatic),
  8. Change settings of nginx (sudo nano /etc/niginx/sites-available/default)…Rewrite server (vultr IP),
  9. Check the settings (sudo nginx -t),
  10. Add vultr IP to .env
  11. Runserver: (python3 manage.py runserver 0.0.0.0:8000)
  12. Enter vultr IP
  13. Stop server
  14. Check gunicorn (gunicorn –bind 127.0.0.1:8000 project.wsgi:application)
  15. —> Enter IP on browser
  16. Register system ctl cmd for start/stop/restart server
  17. —> (sudo nano /etc/systemd/system/project.service)
  18. —>WorkingDirectory=/home/yamaco/src/project
  19. —>ExecStart=/home/yamaco/src/project/myvenv/bin/gunicorn –bind 127.0.0.1:8000 project.wsgi:application
  20. Start server (sudo systemctl start project)
  21. —>Check status (sudo systemctl status project)
  22. —>Stop server (sudo systemctl stop project)
  23. —>Restart server (sudo systemctl restart project)

6. Domain acquisition… 

  1.      —>Name server settings (ns1.vultr.com/ ns2.vultr.com)
  2.      —>Vultr: Add domain to DNS
  3.      —>Add domain to .env
  4.      —>Restart server (sudo systemctl restart project)

Reference: https://www.vultr.com/docs/setup-your-own-dns-server-on-debian-ubuntu

7. HTTPS conversion

  1.      —>Stop server (sudo systemctl stop nginx)
  2.      —>Get a certificate (sudo apt-get install letsencrypt)
  3.      —>Get a certificate (sudo letsencrypt certonly –standalone -d yamaco.work
  4.      —>Change settings of nginx (sudo nano /etc/nginx/sites-available/default)
  5.      —>Check status (sudo nginx -t)
  6.      —>Start nginx (sudo systemctl start nginx)
  7.      —>Restart gunicorn (sudo systemctl restart project)

Recommend

VSC error message: Import “django.db” could not be resolved from source

タイトルとURLをコピーしました