This is an old revision of the document!
Djano Web framework with Gunicorn
On a shared hosting environment with cPanel/WHM installed, we can use Litespeed Enterprise to host Django app on per account basis by proxying content to gunicorn.
Requirments
- You must have a server with cPanel/WHM installed.
- One live domain.
- Litespeed Enterprise installed on top of WHM.
Step 1: Create Django Project
First step is to create your Django project, in this article I assume that you have already created a cPanel account for your domain and its home is /home/litespeed/public_html
Install Django using:
easy_install django
Create a Django project:
cd /home/litespeed/public_html django-admin startproject djangoproject
This will create a folder djangoproject
in the home directory of your domain, this folder contains necessary files to run a Django project.
Before we move our to serve this over Litespeed, we can make sure that our project is created successfully and it's working with Django development server.
Note:
In your django settings file which will be located at /home/litespeed/public_html/djangoproject/djangoproject/settings.py
, you need to allow your current server ip to be in the list of allowed hosts, you can only allow your ip or allow all IPs using:
ALLOWED_HOSTS = ['*']
Or
ALLOWED_HOSTS = ['<IP Address>']
This will allow only your virtual machine IP.
If you do not do this you will receive an error that this host is not allowed to run your Django project, once done run the following command to test your project:
cd /home/litespeed/public_html/djangoproject python manage.py runserver <IP Address>:8000
This command will start Django development server, you can open your browser and enter your IP followed by the port you have used, if you see something like the image below, then you are good to continue with the setup, otherwise, make sure you have followed the steps correctly:
That means your Django project is working fine. On the console press CONTROL-C
to stop the development server so that we can continue with our setup. Please note that this development server does not have to do anything with our setup, it is just to make sure that our Django project is running fine so that later we don’t run into any issues.