How to Easily Set Up Django on CyberPanel

Django on CyberPanel

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.

YouTube video

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.

Facebook
Twitter
Pinterest
LinkedIn
Reddit

Meet Tony

Tony from Tony Teaches Tech headshot

With a strong software engineering background, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

3 Responses

  1. Hi, Currently this method is not working, please create another video or update this page’s documentations to new method of Django deployment on Cyberpanel.
    I tested this method on Ubuntu 22.04 LTS, Python 3.10, And Latest Version of Cyberpanel.

    Date: 1/30/2024

Leave a Reply

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