Find by Category

How to Deploy Python Django App 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. I am using Namecheap shared hosting plan but I would recommend using inMotion which support latest Python 3 and Django version. If you need full root access the server, which you do not get with shared hosting plans, go with VPS hosting provided below.

  1. VULTR for Python
  2. UpCloud for Python Django
  3. Linode for Python Django

Login to your cPanel Account

login to your cPanel
Django Deployment Support Starting from $5

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 Python 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 be 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 anywhere on this page, on mine it’s on the right top.

Create Python Application

View Python App 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 this command, go back to cPanel home page and look up for “TERMINAL” and launch it.

Launch cPanel Terminal

Launch the terminal and paste the command from your clip

Paste the Terminal Command here

Install Django on cPanel

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 cannot 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 Python 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

Navigate to your updated domain name in a new browser tab to check if Django App is loading properly.

Django 3 Course

Learn Django 3 by building project. If you want to learn Django 3 and deploy your application like pros. Sign up for this Django 3 course at affordable price.

Best Python Django App Web Hosting Providers

Here is the list of best Python Django web hosting providers that you may use to host your Python applications as per your requirement.

Shared Hosting for Python Django App

Shared hosting providers offer Python 2 and Python 3 support but some of them would neither guarantee of performance nor guarantee support of latest features of Python or Python framework like Django. You would also have a limitation of using MySQL database, since you can hot install any software of your choice on shared web hosting servers. However, shared hosting is good to test your Python and Django applications.

Here is the list of most reliable shared web hosting providers for Python Apps.

  1. BlueHost
  2. NameCheap
  3. inMotion

Dedicated & Cloud Hosting for Python django App

Dedicated and cloud web hosting will give you more flexibility to install latest and stable versions of python and Python frameworks like Django and flask. Dedicated and cloud web hosting will also let you install the database server of your choice. 

Most importantly you will be able to optimize and tune your applications service for speed and performance. 

Here is a list of best Python Cloud and Dedicated Web Hosting providers.

  1. VULTR
  2. Namecheap 
  3. Bluehost
  4. inMotion

Deploy Django to Heroku

If you would like to deploy your Django app to Heroku server from your system then you need to follow the latest Heroku guide. Remember Heroku does not support all the database servers.

Deploy Django from Git repo

To automatically deploy your Django app from your Git repo you need to first set up and deploy your Django app manually and then use utilize Git actions to keep updating your Django app on the server whenever you update your Django app git repo.

Django Deployment Support Starting from $5

Related Posts.

  1. Python is not recognized
  2. Django 3 Tutorial – Create a Blogging App
  3. Install Django 3 on Windows 10
  4. Install Django on Ubuntu