How to Deploy Django on cPanel – Shared Hosting

In this tutorial, I am going to walk you through how to deploy Python Django web app on a shared cPanel web hosting plan.

Login to your cPanel Account

login to your cPanel

Locate and Launch “Setup Python App”

Under SOFTWARE section you’ll find ‘Setup Python App’. To launch it just click once.

Click SETUP PYTHON APP

Create New Python Application

Now, locate the “Create Application” button and click it

Create Python Application

Create Application

Here you can select Python version, domain or sub domain name, and write your app directory name for your application, I have chosen Python 3.6.8, selected my sub domain name and given app root directory name, which can found from ‘File Manager” page.

Once, you are done with Python version, Application root, and Application URL, click create on the right top. “Create” can be any where on this page, on mine it’s on the right top.

Create Python Application

View in the browser

python app works

Activate Python Virtual Environment

You just created your first Python Application in Cpanel. Now, let’s activate the python virtual environment.

Copy the underlined terminal command

Once you have copied the this command, go back to cPanel home page and look up for “TERMINAL” and launch it.

Launch Terminal

Launch the terminal and paste the command from your clip

Paste the Terminal Command here

Let’s Install Django

To upgrade pip and install Django in this Python Environment I just ran following commands.

pip install --upgrade pip
pip install django==1.9.13

Remember you can install latest version of Django with ==1.9.13 flag, but this is what has worked on my cPanel without any error or issue.

When install and run the latest version of Django on my cPanel it does not find the latest version of SQLite on the server. And on the shared hosting plan I can not upgrade it.

Create Django Project

Let’s create Django project from cPanel Terminal. Type the following command

django-admin startproject project_name .

Don’t forget the period sign at the end

Locate App Root Directory

Locate the app root directory – mine is demo.tubemint.com/

Edit/update /passenger_wsgi.py file with the following code

from project_name.wsgi import application

Save /passenger_wsgi.py file and close it

Edit/Update /project_name/settings.py file

Under settings.py update the ALLOWED_HOST field first

ALLOWED_HOSTS = ['best.tubemint.com', 'www.best.tubemint.com']

Under settings.py update static files section at very bottom of the page

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [BASE_DIR+"/assets",]
STATIC_ROOT = '/home/eatawvtq/public_html/static'
MEDIA_ROOT = '/home/eatawvtq/public_html/media'

Now, you can save and close this settings.py file.

Create Static Files’ Folders in the respective directories

  1. Create /assets/ folder in the project root directory.
  2. Create /static/ and /media/ folders in /public_html/ directory

Run the following command to sync the static files

python manage.py collectstatic

Restart the python server

Navigate to your domain name with browser

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.