Can we host Django websites on cPanel? (Shared Hosting)

Share your love

Django is a versatile Python web framework used to develop simple to complex websites. It is one of the best frameworks used to develop a web application for any project.

Can we host a Django website on shared hosting or cPanel?

You can host Django websites on shared hosting, provided the hosting service supports Python apps. You will find the hosting service advertising the support for Python apps on its hosting plans/packages. Besides, the hosting service should support the databases used by your web application.

Hosting Django on shared hosting is very easy. However, you should ensure that you check some things before purchasing a shared hosting plan

Here is a checklist you need to satisfy before purchasing a shared hosting plan for the Django web application:

  1. The hosting service plan/package supports Python apps
  2. The hosting service advertises support for Python apps on shared hosting and not on VPS
  3. The size of your Django application
  4. The traffic you’re aiming to expect for your web application
  5. The database used by your web application
  6. The hosting service market size

Checklist Number 1: The hosting service plan/package supports Python apps

First, check the hosting service support deployment of Python apps.

You should ensure that the hosting plan/package you purchase supports the deployment of Python apps if you are considering a shared hosting plan.

In this example, you can see that this particular hosting service supports Python apps in some plans and others, they do not provide support for Python apps.

Be sure to select the plan that has support for Python apps.

HostPinnacle hosting packages

You can get yourself a shared hosting plan that supports Python Django with this hosting service.

Checklist Number 2: The hosting service advertises support for Python apps on shared hosting and not on VPS

Although some hosting companies advertise that they support Python apps, the support may be on a shared virtual private server (VPS).

A VPS is a dedicated server used to deploy web applications without sharing computing resources with other users.

In a VPS, you configure the server yourself – install an operating system, configure the system, install Django and its dependencies, install a database, and finally, monitor your web application.

If a hosting service advertises support for Python apps only on VPS packages, then you cannot deploy Django on their shared hosting option.

Checklist Number 3: The size of your Django application

If you have a large Django web application that uses many services and consumes many endpoints, you should not consider deploying it on a shared hosting plan.

Alternatively, consider a virtual private server – Django will perform efficiently in such a setup. 

A web application likely to consume a huge amount of computing power and memory will usually not be efficient in a shared hosting setup. You usually find that the storage, memory, and number of CPUs offered in a shared hosting plan are usually shared across different websites.

Therefore, a large web application will have limited performance, especially during high traffic.

On top of that, resources of a single machine on a shared hosting plan are shared among other users too many websites using the same machine will slow down a large Django web application.

If too many users on the system receive too much traffic, your Django application may lag due to the ‘stretched’ computer resources.

An alternative is to choose a hosting provider that deploys huge resources for a single virtual server.

One perfect choice for hosting large Django web applications is Digital Ocean.

  • They are affordable
  • You pay for the resources you use

Use this link to get a discount and credit for the first 12 months you host with them.

OR

Consider a virtual private server.

A shared server will work just fine for a simple Django web application.

This hosting service provides a great setup that allows you to host Django on their shared hosting servers.

Checklist Number 4: The traffic or number of users you’re aiming to serve with your web application

The same goes for the size of traffic your web application is likely to receive.

If your Django web application is likely to be used by tens of thousands of users daily, then the shared hosting computer resources will be ‘overstretched’.

Your Django application will be slow, especially if other websites using the same machine receive large traffic.

Deploy your Django web application on a virtual private server if you expect a large number of users to access your website simultaneously. 

If your Django application will serve a limited number of people, like a few thousand per day, then shared hosting will be a better option, especially considering the cost.

Checklist Number 5: The database used by your web application

Most shared hosting service providers use MySQL as the primary database for the websites deployed on their servers.

Your web application uses MongoDB or PostgreSQL as the primary database. In such a Django setup, you cannot deploy your web application on a hosting service that does not provide a database used by your web application.

Before purchasing a shared hosting plan, check that the plan/package you’re purchasing supports the database used by your web application. Communicate with the technical team of the hosting company to be sure.

Checklist Number 6: The hosting service market size

As I have mentioned, a single machine in a shared hosting setup is distributed among various users that have purchased packages from the hosting provider.

Therefore, if a company’s market size is large, a single machine can be shared by too many users leading to a reduction in the efficiency of the server. 

Therefore, consider a hosting service with a good reputation and has exploited a small market size. Consider looking at the hosting services this company provides – it has a good reputation and a small market size.

How do you host a Django web application on Shared Hosting?

Hosting Django on shared hosting involves these steps: logging in to the cPanel, creating a new Python app, configuring the app’s environment variables, uploading the Django project’s files and folders, configuring the connection details of your app to the database, and finally instructing the passenger_wsgi of the hosting service to use the Django projects wsgi app.

Here are the detailed steps:

Step 1: Log in to your cPanel account

Login to your cPanel account

Log in to your cPanel account, search for ‘set up python app’, and follow the link.

Step 2: Setup a new Python app

Set up new python app on cPanel

Select the version of Python you will use for your Django application.

 Select the folder where you will upload the project’s files and folders. Also, ensure the application URL uses the domain name you want to choose for your web application.

Configuring a new Django application on cPanel

Step 3: Configure the environment variables used by your Django application

Using Django environment variables on cPanel

Use environment variables to store sensitive information. It is safe to store sensitive information such as the Django project’s secret keys, database connection details, and APIs connection details.

Enter this information and use Python Decouple to access these values.

Never hard code sensitive information on your code.

Step 4: Set up a new database, store the connection details as environment variables, and use these values on your Django application.

Create a new database using the cPanel interface. While creating the database, note the database name, password, and user. Use these values in your Django application.

Be sure to run migrations after adding a new database to your Django web application.

Step 5: Connect your Django application with the passenger_wsgi app

The passenger_wsgi.py should look like this




sys.path.insert(0, os.path.dirname(__file__))


def application(environ, start_response):
     start_response('200 OK', [('Content-Type', 'text/plain')])
     message = 'It works!\n'
     version = 'Python %s\n' % sys.version.split()[0]
    response = '\n'.join([message, version])
    return [response.encode()]

Comment out everything on this file and replace it with the following lines of code:

import os
import sys


# sys.path.insert(0, os.path.dirname(__file__))


# def application(environ, start_response):
#     start_response('200 OK', [('Content-Type', 'text/plain')])
#     message = 'It works!\n'
#     version = 'Python %s\n' % sys.version.split()[0]
#     response = '\n'.join([message, version])
#     return [response.encode()]

from YourProjectName.wsgi import application

Be sure to enter the correct name for your Django project. Your Django web application is live. Confirm that the application is accessible using the domain name you set at the beginning of this article. If you are new to Django, check out this resource that has a guide on how to learn Python/Django.

This article provides more details on how to set up a Django application on shared hosting.

And don’t forget to check on this hosting provider that provides servers for hosting Django at very low prices.

Struggling to find affordable hosting for your Django web application?

This hosting service offers a cost-effective solution that is tailored for

  1. VPS hosting for Django
  2. Shared hosting for Django

Allowing you to:

🚀 Supercharge Your Ideas: Worried about investing too much upfront? Our affordable shared hosting lets you test and validate your innovative concepts created using Python Django without draining your budget.

🎯 Lure and Impress Clients With an Already Deployed Django Project: You just need one hosting plan to host unlimited Django websites.

⚙️ Hassle-Free Setup: With the user-friendly interface, you’ll have your Django project up and running in minutes with this Django-ready optimized host. Besides, I have written an article for you to use to deploy your Django app, here.

Act now while there is a huge discount on their hosting plans. Use the link below

Secure Your Hosting Server Now!

That’s it for this article. I hope to see you next time.

Share your love
Badi
Badi

Badi here, creator of ngangasn.com— A website dedicated to providing helpful information and how-to's of web development and hosting. Inspired by a fascination to write the most efficient code to make a computer laugh, & humans, Steve has a passion for organizing characters to create code and informative content.
What makes me happy?
Well, nothing like the feeling of finally figuring out that one pesky bug that's been driving me crazy.

Leave a Reply

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