Skip to content

Instantly share code, notes, and snippets.

@viral-sangani
Last active March 27, 2020 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viral-sangani/546552f74336326569061a3acc9f6f5d to your computer and use it in GitHub Desktop.
Save viral-sangani/546552f74336326569061a3acc9f6f5d to your computer and use it in GitHub Desktop.
Django Config Steps

Steps to Make you Django Project Online (from Scratch)

* Note You need to have your Django project ready and start a server in any hosting website (aws, azure, ..) and login through SSH

  • Step 1 :- Become Root in your server - sudo su
  • Step 2 :- cd /
  • Step 3 :- apt update && apt upgrade -ya
  • Step 4 :- mkdir -p /<Project Name>/site/logs /<Project Name>/site/public /<Project Name>/django /<Project Name>/auth -> create folders
  • Step 5 :- apt install python3-pip -y
  • Step 6 :- pip3 install virtualenv
  • Step 7 :- cd /<Project Name>; virtualenv venv -p /usr/bin/python3
  • Step 8 :- source venv/bin/activate
  • Step 9 :- cd django;git clone <Project Repo Link>
  • Step 10 :- pip install -r <Project Name>/requirement.txt
  • Step 11 :- Add Server IP to Setting.py Allowed Host
  • Step 12 :- Check where setting till now is OK? Go in Project Folder python manage.py runserver 0.0.0.0:8000
    • Note : Add 8000, 80, 443 in Security Group Inbound in case of AWS

Apache2 Section

  • Step 13 :- apt install apache2 libapache2-mod-wsgi-py3 -y
  • Step 14 :- cd /etc/apache2/sites-available/
  • Step 15 :- Edit 000-default.conf with appendix-1 (blow) -> apache2 config file for Django
  • Step 16 :- service apach2 restart
Done

Appendix - 1

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html


        ErrorLog /<Project Name>/site/logs/error.log
        CustomLog /<Project Name>/site/logs/access.log combined

        <Directory /<Project Name>/django/secure-cloud-storage/<Project Name>>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIDaemonProcess <Project Name> python-path=/<Project Name>/django/secure-cloud-storage python-home=/<Project Name>/venv
        WSGIProcessGroup <Project Name>
        WSGIScriptAlias / /<Project Name>/django/secure-cloud-storage/<Project Name>/wsgi.py

</VirtualHost>```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment