Header Ads

Python Django Webserver Hosting on Google Cloud Console , Google App Engine

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 Django project we need to create a list of libraries that we have used in our 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 setup. So, let's start:

Django Project Overview : 

Here we continue deploying our Python Django with Google Firebase series Django Project in which we have create a Employee Daily Progress Reporting System which uses different-different Firebase Functionalities such as : Firebase Authentication for Login the user, Firebase Database for Read\Write operations like storing reports data create by user, Firebase storage for uploading images, docx to be uploaded by user & at last but not the least Firebase cloud messaging : For sending automated push notification to Admin Android App once report created by user.  

Steps below follows the video to help :

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\
In next step we have to Setup Google Cloud Console and Vm Instance done in previous post.

Setup Google App Engine Vm instance:

Go to Google Cloud Console navigate to compute engine -> Vm instance -> create instance  :

Add relevant information make sure in firewall tab :
  • Allow HTTP traffic
  • Allow HTTPS traffic
that's it click on create button and run vm instance and get SSH access.

Now install pip3 in vm instance typing following command in ssh terminal -

  • sudo apt-get install python3-pip

Setup SCP ssh key :

Now, we need to transfer our Django project from workstation to Vm instance for which we are having diffrent ways like using Github | Bitbucket, SCP & using Google cloud sdk. Using SCP is one of my favourite one but there issue of version control also for which you can intialize git.

  Generate a 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]:~

above command transfer Django project from Workstation\Host machine to Vm instance. 

Setup Django Project on Vm instance :

Now, Django project is on vm instance let's extract the tar.gz file and live our django Web-App.

  • tar -xvzf cpanel.tar.gz
  • cd cpanel  

as we have already installed pip3 in previous steps, navigate to req.txt file created for getting list of libraries used for creating Django project. Run the below command to install all libraries in one go

  • 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.

For testing run Django on, as django server will stop if we close the terminal we need to run it as background process

  • sudo python3 manage.py runserver

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 

there might be conditions you need to kill nohup process for server upgrade use kill command.

  • ps -ef | grep python3 manage.py runserver
  • killl process id.


  1. 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

  2. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. Unlimited websites

  3. This blog through it words has given a key to proficiency.
    Microsoft project alternative

  4. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative.
    Minneapolis Web Design Company

  5. Wow i can say that this is another great article as expected of this blog.Bookmarked this site.. ddos mitigation

  6. 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/

  7. Thanks for the blog post buddy! Keep them coming... www.dedicated-servers.com

  8. This is such a great resource that you are providing and you give it away for free. app store screens

  9. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. Balance Bar Ball Head

  10. 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

  11. As of now, massage course providers advertise online to attract clients to enroll in their cursos de ti online

  12. nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this! Reseller Hosting

  13. 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

  14. Nice post, keep up with this interesting work. It really is good to know that this topic. You should cover also the best wordpress hosting 2020 also because its a well known topics in 2020. Also the each web hosting reviews like the bluehost reviews 2020 and the other hostings like the hostgator, liquid web and etc.

  15. Cool you write, the information is very good and interesting, I'll give you a link to my site. en Venezuela

  16. Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work. bestarkserverhosting.com

  17. Hey, what kind of anti-spam plugin do you use for your blog.:~*’- la web design

  18. “I’m a newbie and your accomplishment is quite a lot an inspiration for me” web designer la


Powered by Blogger.