This is an old revision of the document!

Python Django: How to set up Django when LSWS reads apache conf

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 official slogan says “the web framework for perfectionists with deadlines”.

In this tutorial, we will see how we can setup a DJANGO application when LSWS reading apache configuration instead of native, such as a Cyberpanel environment. LSWS will use mod_passenger directives in virtual host's doc_root .htaccess to define the application.

Before moving forward, you need to install CyberPanel and Create Website. If CyberPanel is already installed, make sure to upgrade LSWS to the latest version.

Install python3 on CentOS

yum install python3-devel
yum install python3-pip

Install python3 on Ubuntu

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

Create your domain on Cyberpanel, such as, it should locate at /home/ and owned by user “cyberdj:cyberdj”

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

Download the latest version of wsgi-lsapi from

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 virtualevn in the user’s home directory. For best practice, virtualevn should not be in domain’s document_root.

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

If you already have DJANGO application you can create a project folder, for example app1, at /home/ and move your exiting application to to it. We will create a brand new DJANGO project named “app1”

cd /home/
django-admin startproject app1

Edit your project settings:

vi /home/

make sure allowed hosts looks like:


Create static files directory, normally static files be placed inside doc_root, you can create /static/ directory at doc_root first.

mkdir /home/

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

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

then you can go to your project directory and run a few commands to start collect static files and create super user.

cd /home/
python3 collectstatic
python3 migrate
python3 createsuperuser

To define django application, LSWS will use mod_passenger directives in virtual host doc_root .htaccess. Directives can be used by LSWS:

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

You can create .htaccess if it doesn't exist yet.

You can place the following in .htaccess:

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/14 20:24
  • by Jackson Zhang