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…
- Add user, Update Ubuntu (sudo apt update/ sudo apt upgrade),
- Install (sudo apt install nginx python3-pip python3-venv),
- Make a folder (mkdir src),
- 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
- Copy CODE,
- cd src: git clone <git CODE url>,
- Open copied folder on VSC,
- Virtual env (python3 -m venv myvenv),
- Activate env (source myvenv/bin/activate)
Visit Github: https://github.com/
5. Deploy…
- Update (pip3 install –upgrade pip setuptools),
- Install requirements (pip3 install -r requirements.txt): local and myvenv,
- Make a directory for static (sudo mkdir /usr/share/nginx/html/static),
- Make a directory for media (sudo mkdir /usr/share/nginx/html/media),
- Make .env file for environment variable (write: SECRET_KEY=xxxxx/ ALLOWED_HOSTS=127.0.0.1),
- Migrate (python3 manage.py migrate),
- Collectstatic (sudo python3 manage.py collectstatic),
- Change settings of nginx (sudo nano /etc/niginx/sites-available/default)…Rewrite server (vultr IP),
- Check the settings (sudo nginx -t),
- Add vultr IP to .env
- Runserver: (python3 manage.py runserver 0.0.0.0:8000)
- Enter vultr IP
- Stop server
- Check gunicorn (gunicorn –bind 127.0.0.1:8000 project.wsgi:application)
- —> Enter IP on browser
- Register system ctl cmd for start/stop/restart server
- —> (sudo nano /etc/systemd/system/project.service)
- —>WorkingDirectory=/home/yamaco/src/project
- —>ExecStart=/home/yamaco/src/project/myvenv/bin/gunicorn –bind 127.0.0.1:8000 project.wsgi:application
- Start server (sudo systemctl start project)
- —>Check status (sudo systemctl status project)
- —>Stop server (sudo systemctl stop project)
- —>Restart server (sudo systemctl restart project)
6. Domain acquisition…
- —>Name server settings (ns1.vultr.com/ ns2.vultr.com)
- —>Vultr: Add domain to DNS
- —>Add domain to .env
- —>Restart server (sudo systemctl restart project)
Reference: https://www.vultr.com/docs/setup-your-own-dns-server-on-debian-ubuntu
7. HTTPS conversion
- —>Stop server (sudo systemctl stop nginx)
- —>Get a certificate (sudo apt-get install letsencrypt)
- —>Get a certificate (sudo letsencrypt certonly –standalone -d yamaco.work
- —>Change settings of nginx (sudo nano /etc/nginx/sites-available/default)
- —>Check status (sudo nginx -t)
- —>Start nginx (sudo systemctl start nginx)
- —>Restart gunicorn (sudo systemctl restart project)
Recommend
VSC error message: Import “django.db” could not be resolved from source