Web Hosting Blog by Nest WebHost | Domain & Hosting Tips
deploy django app in cpanel

Deploy Django Project in cPanel Easily in 5 minutes

deploy django app in cpanel

Deploy or Host Django Project in Cpanel

This blog will walk you through the process of deploying and setting up a Python app or Django project in Cpanel. Lets Starts …

Let’s Make the Django Project Ready for Production with a few pre steps

Creating Requirements A Text File which contains all the necessary modules used in the Django Project

  1. Have a virtual environment activated
  2. Open up terminal in same project dir.
  3. The Run command pip freeze > requirements.txt this will place all of the module names and versions which you have installed in your environment.

Lets start by deploying the Django project in cpanel.

  1. Upload your project to github
  2. Copy repo url
  3. Open terminal from Cpanel Main page
  4. Terminal opens in home dir, clone project in home dir.git clone repo_url
Login or Open your Control Panel. Go to the file manager and upload your project. Note: You need to zip the file before uploading it, then after you need to unzip it again. overwhelming huh? Go with the GitHub one. Creating a Python App in Cpanel

Creating Python Apps (Django App)

Go to the main page of Cpanel, search for setup python app , open it.

Setup Python app

Now here you need to fill in the requested info. Application Root-name of your project folder which you have uploaded in your home dir before Application Url-Url/domain url of your app. I kept the same And to create your app, click on the blue create button there. After that, this will look like this: Setup Passensger_wsgi.py

Setting up the passenger_wsgi.py file

This file is created in same project folder by cpanel while setting up python app locate the file, it is present in home dir > yourprojectfolder Click once on that file. Once on, the Edit button will appear in the top bar. Edit it. put from .wsgi import application Done… Note: yourprojectfolder i mean the folder which contains settings.py ,wsgi.py, asgi.py etc..

Installing modules or requirements in virtual environment

click the virtual environment path it will copy it, which you will see in the top after creating a Python app. Open the terminal and go to the project folder. command goes cd hit enter, and then paste the environment path you just copied and hit enter. The run command pip install-r requirements.txt will install all the listed modules in files.

The most important steps to finalize the setup

Edit your settings.py file, search for ALLOWED_HOSTS = [] Make it such ALLOWED_HOSTS = [“*”] or you can replace * with your websiteurl for example.www.itsnp.org

Setting up static and media files for production of the Django project

the is the most overwhelming steps.. This is how it looks before in most cases. Now we are going to change this for production. STATIC_URL = “/static/” STATICFILES_DIRS = [BASE_DIR / “static”] STATIC_ROOT = BASE_DIR / “staticfiles” # need to change this MEDIA_URL = “/media/” MEDIA_ROOT = BASE_DIR / “media” # need to change this
  1. STATICFILES_DIRS:  This isThe following is a list of all the directories where folders containing static files are present.
  2. STATIC_ROOT : This is So serve as the folder where all of the static files are production foldercollected later on in production.
  3. MEDIA_ROOT: Same goes for media root also.. all the uploaded files are saved in media root.
When a Python When you create a Python app from cpanel, another folder with your application name is created inside your domain or submdomain folder. In my case, this is how it is created. In my case,
And inside the petpup folder of a subdomain or domain, all the root folders like STATIC ROOT, MEDIA ROOT are created and served in production. So now this is how it will look after replacing BASE_DIR with the absolute path of the applicationfolder inside of a subdomain or domain.
STATIC_URL = "/petpup/static/"
STATIC_ROOT = "/home1/itsnporg/sachit.itsnp.org/petpup/staticfiles"
MEDIA_URL ="/petpup/media/"
MEDIA_ROOT = "/home1/itsnporg/sachit.itsnp.org/petpup/media"
Now Django will search for all of the static and store media files in domain/appname/folder This might be so overwhelming to get it as a beginner.

Almost Done

Simply Click Restart and click Open button and you will see your app running.. If not yet let me know in the comment i will surely help you out

Where to get profesional help with django?

If you’re finding it challenging to navigate the intricacies of deploying a Django project on cPanel, it might be time to bring in the experts. Webisoft is an excellent option for those who require professional assistance. Not only do they specialize in Django deployment, but they also offer a comprehensive suite of services that cover everything from initial setup to ongoing maintenance. Their experienced team can take you through each step, from setting up the virtual environment and installing necessary modules to configuring static and media files for production. Webisoft’s end-to-end services ensure that you can focus on what you do best, leaving the technicalities to them. With a reputation for excellence and a commitment to customer satisfaction, Webisoft can help turn your Django project into a smoothly functioning, live application.
Share this article
Shareable URL
Prev Post

WordPress Hosting in Nepal

Next Post

Web Hosting in Nepal: Best Web Hosting in Nepal in 2023

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next