Deploying a website online always become a cramp-breaking task, as we need to prepare web-server code for production environment, if we talk about a Python Django project we need to create a list of libraries that we have used in our Python Django project, need to edit configuration files and in some cases there is need for changing urls also. In the post we will see step by step guide for hosting Django project on Google cloud console i.e Google App Engine, whole process will take at max 30 minutes to set up. So, let’s start:
Django Project Overview :
Setup Django Project for Hosting:
First step is make a list of libraries, installed while creating your Django Project. Here is bonus tip, every-time starting your Python Django Project create & activate virtual environment this will isolate installed libraries.
- pip freeze >req.txt
Above command create file named req.txt which includes the list of libraries used in our project. Now just paste this file where in Project directory and create a compressed tar file .
- tar -cvzf cpanel.tar.gz cpanel
Setup Google App Engine Vm instance:
- Allow HTTP traffic
- Allow HTTPS traffic
Now install pip3 in vm instance typing following command in ssh terminal –
- sudo apt-get install python3-pip
Setup SCP ssh key :
- ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME] -C [USERNAME]
- Example: ssh-keygen -t rsa -f ~/.ssh/key -C Linux
- cat ~/.ssh/key.pub
above commands will create and show a public ssh key that you have to add in Google cloud console.
Go on Google Cloud dashboard and navigate to compute engine -> metadata -> ssh keys -> edit
here add ssh key you got in previous step .
Using scp command for transferring files :
- scp -i ~/.ssh/my-ssh-key [LOCAL_FILE_PATH] [USERNAME]@[IP_ADDRESS]:~
Setup Django Project on Vm instance :
- tar -xvzf cpanel.tar.gz
- cd cpanel
- sudo pip install -r req.txt
So, here comes our final step for which we are waiting let’s run our Django project use below command and access your live website on vm instance public I.P. address.
- sudo python3 manage.py runserver 0.0.0.0:80
There are too many ways for running django in background, i personally prefer Nohup command for running project in background.
- sudo nohup python3 manage.py runserver 0.0.0.0:80
there might be conditions you need to kill nohup process for server upgrade use kill command.
- ps -ef | grep python3 manage.py runserver 0.0.0.0:80
- killl process id.
Thank you Kevin Sharma for all your tutorial on django ! It really is helpfull
Can you make one about activating HTTPS on django ?
Thank you very much
This blog through it words has given a key to proficiency.
Microsoft project alternative
This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post! https://axndata.com/
This is such a great resource that you are providing and you give it away for free. app store screens
I love visiting sites in my free time. I have visited many sites but did not find any site more efficient than yours. Thanks for the nudge! ecommerce web hosting
As of now, massage course providers advertise online to attract clients to enroll in their cursos de ti online
If your web site goes down in the middle of the night when they're not available, this means lost revenue for a business. You should make sure the web host you select is always available for support.unturned server hosting
Cool you write, the information is very good and interesting, I'll give you a link to my site. en Venezuela