How to Easily Set Up Django on CyberPanel

by

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

In this quick tutorial, you will learn how to set up Django on CyberPanel that’s running on an OpenLiteSpeed web server. This assumes you are running Ubuntu/Debian and have root SSH access to the server.

1. Install Litespeed WSGI

First update your system and install a couple dependencies.

apt-get install build-essential
apt-get install python3-dev

Next, download the Litespeed web server gateway interface archive. Extract it, build it, and install it as a binary to the system.

curl -O http://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.7.tgz
tar xf wsgi-lsapi-1.7.tgz
cd wsgi-lsapi-1.7
python3 ./configure.py
make
cp lswsgi /usr/local/lsws/fcgi-bin/

2. Install a Python Virtual Environment

Let’s make a virtual environment for our Python website.

virtualenv --system-site-packages /home/site1.xyz/public_html
source /home/site1.xyz/public_html/bin/activate

3. Install and Start a Django Project

Use the pip package manager to install Django in your virtual environment.

pip3 install django

In your website’s public directory, start a Django project with the django-admin command.

cd /home/site1.xyz/public_html
django-admin startproject demoproj

For testing, allow all hosts in website’s settings.py file.

ALLOWED_HOSTS = ['*']

4. Update the vhosts Configuration

For your website in CyberPanel, add the following to the bottom of your site’s vhosts file.

context / {
  type                    appserver
  location                /home/site1.xyz/public_html/demoproj
  binPath                 /usr/local/lsws/fcgi-bin/lswsgi
  appType                 wsgi
  startupFile             demoproj/wsgi.py
  envType                 1
  env                     LS_PYTHONBIN=/home/site1.xyz/public_html/bin/pyhton
  env                     PYTHONHOME=/home/site1.xyz/public_html/
}

After restarting the server to apply changes, you should be able to navigate to your website’s URL in a web browser and see the default Django landing page.

Check out some of these other Django tutorials here to get started with developing your Python website and preparing it for release to the public.


Meet Tony

With a strong software engineering background, Tony is determined to help as many people as possible start their online busines. Discover why Tony quit his hedge fund job to pursue this mission. You can send Tony a message here.

Leave a Comment