abhilashthale.com
  • Home
  • BlogCategories
    • coding
    • other
  • Images to Pdf
  • Shares Average
  • About Me

    How To Setup Django Site In Linux Vps

    by abhilash - March 15, 2021

    1) Buy a VPS Server

    for setting up django web app in centos/RHEL vps system you hve to buy vps server from vps provider it will give you server ip address and root password  also you will get  client web gui for management of server from that you get access to  reset server ,reinstall server or boot sever into safe mode and  from there you can even change the root password

    2) ssh the server

    now ssh the sever from any ssh client like putty ,cmd or mobxtrem,etc.

    e.g ssh root@192.168.47.101 ---> give root password of server

    after that you will get the full access that server

    3)Change the root password

    once you login to ssh server you should change  your root password by passwd commnad

    e.g passwd root --> give new password two times

    4) add a new user

    add a new user so you dont needed to use root for all the times it will make your server more secure 

    e.g useradd test  

    passwd test -->  give new password two times

    now add that test user to wheel group so you can use sudo command by sudo command you can access all system  command with normal user

    e.g usermod -G wheel test

     

    root is all powerfull user you should  never allow directly access

    5) Configure ssh

    configure ssh so  no one can login to the system via root  , edit  ssh configuration file and write PermitRootLogin to No

     

    e.g  vim   /etc/ssh/sshd_config

           PermitRootLogin to No

    now reboot the system and login via ssh  by ssh user@server

     

    6)update the system 

    now update the system then reboot the system

    e.g yum update && reboot

    7)Install python3

    after sucessfully update install python3

    e.g yum install python3

    8)install and activate virtual enviroment

    after installation of python3 we can use python pip package installer by using pip we can install and create virtual enviroment

    by using virtual enviroment we can install python packages virtually that means they only available when we activate the virtual enviroment 

     

    e.g pip3 install virtualenv

    9)activate virtual enviroment

    for activation of virtual enviroment  create new directory use source command to activate it

    e.g  mkdir /djangoenv

    virtualenv /djangoenv

    source /django/bin/activate

    10)install python packages

    first create the requirement.txt in that file it have list of names of python packages

    now install it by 

    e.g pip install -r requirements.txt

     

    11) install sqlite3.8 

    for django to work in python3 linux we need the sqlite version 3.8

    wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm
    
    sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm
    

     

    12)copy django application to server

    copy django application to server by using scp or sftp

    e.g scp djangoapplication.zip user@server

     

    13)test the django application

    python3 manage.py runserver

     

    14)install apache webserver

    install apache webserver

    yum install httpd*

     

    15) configure apache server

    go to /etc/httpd/conf.d 

    create web.conf file

    type configuration

    <virtual host *:80>

    servername yoursitename

    alias /static  /your static directory in django application

    alias /media /your media directory in django application

    <directory  /your static direcory >

    require all granted

    </directory>

    <directory  /your media directory >

    require all granted

    </directory>

    <directory /your main app directory where wsgi file located>

    <files wsgi.py>

    require all granted

    </files>

    </directory>

    WSGIDaemonProcess name_of_your_project python-path = /directory of project

    python-home = /directory of enviroment variables'

    WSGIProcessGroup  name_of_project

    WSGIScriptAlias / /your django app directory

    </virtualhost>

    save and exit

    if there is numpy python package in your django app then it will gives time out so add following line to

    /etc/httpd/conf/httpd.conf

    WSGIApplicationGroup % {GLOBAL}

    save and exit

     

    16)Restart apache server

    test apache config by 

    apachectl configtest

    restart apache server 

    systemctl restart httpd

     

    17)go to web browser check your site 

    yes

     

     

     

     

     

     

     

     

     

abhilashthale.com