Categories
Django

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.

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

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

Dedicated & Cloud Hosting for Python 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. Digital Ocean 
  2. Namecheap 
  3. Bluehost
  4. SiteGround

By Tube Mint

I am a YouTuber and I also do niche marketing. In the process of create my niche blog using WordPress, Drupal, and GatsbyJS, I learned a few things like html, css, JS, CMS, MVC frameworks, C++, Python, Ruby, MySQL, Windows and Linux. After some time.. I realized that I can share my knowledge with people on YouTube and through my blog. So, here I am. You can ask me if you have any question about these technologies.
Thanks,
@TubeMint