Previous

Django Project Deployement On VPS

Next

How to get server access:

ssh username@ip_address

 

For Example :

ssh ram@111.222.333.444

Then ender  your password

clona the repository

git clone <path>

username : xxxx

password : xxxx

create virtual environ ment

python3 -m venv env

 

Activate the virtual environment

 

source env/bin/activate

 

Instal Project dependance

 

pip install -r requirements.txt

 

Upload the file from local to server

scp <filename> ssh <username>@<ip-address>:<destination path>

 

python manage.py runserver 0.0.0.0:8000

System check identified no issues (0 silenced).
October 19, 2024 - 12:25:28
Django version 5.1.2, using settings 'project_name.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

now you can access the project by ip address and port no

ip_address:8000

 

Install gunicorn

 

$ pip install gunicorn

 

Configure conficorn

$ gunicorn --bind 0.0.0.0:8000 project_name.wsgi

Once bind then will get pid

 

[2024-10-19 12:32:29 +0000] [654321] [INFO] Starting gunicorn 23.0.0
[2024-10-19 12:32:29 +0000] [654321] [INFO] Listening at: http://0.0.0.0:8000 (123456)
[2024-10-19 12:32:29 +0000] [654321] [INFO] Using worker: sync
[2024-10-19 12:32:29 +0000] [654321] [INFO] Booting worker with pid:123456

 

then exit

 

Confifure socket file

 

[Unit]
Description=gunicorn socket for proejct_name

[Socket]
ListenStream=/run/gunicorn-project_name.sock

[Install]
WantedBy=sockets.target

 

Create Service File

 

$ sudo nano /etc/systemd/system/gunicorn-scheme_lms.service

[Unit]
Description=gunicorn daemon for project_name
Requires=gunicorn-project_name.socket
After=network.target

[Service]
User=ram
Group=www-data
WorkingDirectory=/project/path/here
ExecStart=/project/path/here/env/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          project_name.wsgi:application
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target

 

Configure the domain here

Configure Nginx as a Reverse Proxy

$

sudo nano /etc/nginx/sites-available/project_name

 

server {
    server_name domain or ip;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /project/path/here;
    }
    location /media/ {
        root /project/path/here;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn-project_name.sock;
    }

}

Activate the Configuration :

$ sudo ln -s /etc/nginx/sites-available/project_name /etc/nginx/sites-enabled

 

Check nginx Configuration

$ sudo nginx -t

Restart gunicorn service

 

$ systemctl restart gunicorn-project_name.service

 

Restart Nginx

$ systemctl restart nginx

 

 

Add ssl

for installation

 

$ snap install --classic certbot

 

command to setup ssl in domain

 

$ sudo certbot --nginx

 

 

How To Take Backup From Hostinger Server To Local System

 

By using scp command

scp -r ram@<ip>:<servicebackup file or folder path> ~/<local path>/

For Example:-

In local system create directory called backup

Like this

mkdir ~/backup/

 

scp -r ram@<ip-address>:/home/ram/HIMSBU12thA.zip ~/backup/

 

How to create zip file on server/local system

zip -r <backup.zip> <project name that need to zip it>

 

For Example ➖

zip -r  <file_name.zip> <folder name>

 

If zip is not installed then run below command to install it

sudo apt install zip