Set up Django With LSWS in CyberPanel

Django is a web application framework built with Python. Django has seen tremendous growth recently, and a lot of developers are moving towards this framework. Django's official slogan is “the web framework for perfectionists with deadlines.”

In this tutorial, we will set up a Django application for LiteSpeed Web Server with CyberPanel. We will use mod_passenger directives in a virtual host's document root .htaccess to define the application.

NOTE: These instructions also apply if you have manually set LSWS to read Apache config. They do not, however, apply to LSWS with other control panels (like cPanel or Plesk). For those, we recommend using CloudLinux Python selectors.

  • Up-to-date installation of CyberPanel
  • Up-to-date installation of LiteSpeed Web Server


yum install python3-devel
yum install python3-pip


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

Create your domain on CyberPanel. For this example, let's use, put it in the /home/ directory and make the owner be cyberdj:cyberdj, like so:

drwx--x--x 5 cyberdj    cyberdj    4096 Aug  3 16:30

Download the latest version of wsgi-lsapi.

Run the following commands:

Cd  root
curl -O
tar xf wsgi-lsapi-1.6.tgz
cd wsgi-lsapi-1.6
python3 ./
cp lswsgi /usr/local/lsws/fcgi-bin/

We will setup virtualenv in the user’s home directory. To adhere to best practices, don't put virtualenv in the domain’s document root.

Su - cyberdj
virtualenv --system-site-packages /home/
source /home/
pip3 install django

If you already have a Django application, you can create a project folder, for example app1, at /home/, and move your existing application into it.

For this example, we will create a brand new Django project named app1.

cd /home/
django-admin startproject app1

Edit the project settings:

vi /home/

Make sure allowed hosts looks like this:


Create a static file directory. Normally static files are placed inside the document root, so you can create a /static/ directory in doc root:

mkdir /home/

To set the path for static files, add the following at the end of

STATIC_URL = '/static/'
STATIC_ROOT = '/home/'  

Visit your project directory. Run a few commands to start collecting static files and create super user:

cd /home/
python3 collectstatic
python3 migrate
python3 createsuperuser

To define a Django application, LSWS will use mod_passenger directives in the virtual host's doc root .htaccess. These directives can be used by LSWS:

  • PassengerBaseURI
  • PassengerAppRoot
  • PassengerAppEnv
  • PassengerAppType
  • PassengerStartupFile
  • PassengerPython
  • PassengerRuby
  • PassengerNodejs
  • PassengerUser
  • PassengerGroup

Place something like the following in .htaccess (create the file if it doesn't exist):

PassengerAppRoot "/home/"
PassengerBaseURI "/"
PassengerPython "/usr/local/lsws/fcgi-bin/lswsgi"
PassengerAppEnv "Production"
# Add SetEnv to pass extra environments to the application
  • Admin
  • Last modified: 2020/08/17 19:29
  • by Lisa Clarke