Written by 1:00 pm Web Hosting

Deploy Django Project in cPanel Easily in 5 minutes

deploy django app in cpanel
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

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

(Visited 2,823 times, 7 visits today)

Last modified: May 26, 2022