OpenLiteSpeed is an optimized open source web server that can be used to manage and serve sites. Django is a high-level open source Python web framework that enables rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. Here we’ll combine two amazing technology along with emerging database backend, Postgres
In his article i will guide you how to deploy your django app to production server. I will be using a Ubuntu 20.04 VPS to deploy my Django app and PostgreSQL for the database. You will need an Ubuntu 18.04 or 20.04 server with a
sudo– enabled and the
ufw firewall enabled. You can setup your own vps from Digitalocean. Click here for 100$ credit.
As the first step, you need to login to your vps using ssh from your device. And then start installing the essential packages.
Install Python and Package compiler
Install build–essentials package. It is a meta-package that installs many other packages, like G++, GCC, dpkg-dev, make,etc.
$ apt install build-essential
If you haven already installed Python3 development pacakge then you can skip this step.
Install python3 and development tool need to compile python packages.
$ apt-get install python3-dev
We will now install OpenLiteSpeed Server in our VPS. First lets add the litespeed repository to our list.
$ sudo add-apt-repository 'deb http://rpms.litespeedtech.com/debian/ bionic main' $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 011AA62DEDA1F085 $ apt-get install openlitespeed lsphp73
We can install the openlitespeed and PHP package using following command. *Read note below
$ apt-get install openlitespeed lsphp73
*NOTE: If you encountered an error regarding libzip4 installation run this command and run above command again.
$ echo deb http://archive.ubuntu.com/ubuntu/ bionic universe | sudo tee /etc/apt/sources.list.d/bionic.list $ sudo apt-get update $ sudo apt-get install libzip4
Openlitespeed generally start automatically after installation. However you can check the status using
$ sudo /usr/local/lsws/bin/lswsctrl status Output litespeed is running with PID 12248.
lswsctrl also provides
start, restart and
If you have firewall enabled in your vps you need to allow two ports which will be used later to access Webadmin panel of Openlitespeed.
$ sudo ufw allow 8088 $ sudo ufw allow 7080
Create account for Openlitespeed
$ sudo /usr/local/lsws/admin/misc/admpass.sh
This will allow you to set username and password for your account which can be used to login the webadmin console of openlitespeed. You will be asked to provide a username for the administrative user. If you press
ENTER without choosing a new username, the default of admin will be used. Then, you will be prompted to create and confirm a new password for the account. Do so, then hit
ENTER one last time. The script will confirm a successful update:
Install LSWSGI API(WSGI provided by Litespeed)
WSGI(Web Server Gateway Interface) is interface between Python application and the server. We will be installing WSGI provided by litespeed. Run the following command one by one.
$ curl -O http://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.6.tgz $ tar xf wsgi-lsapi-1.6.tgz $ cd wsgi-lsapi-1.6 $ python3 ./configure.py $ make $ cp lswsgi /usr/local/lsws/fcgi-bin/
So you are ready with Litespeed and WSGI to run your Django project.
Now, You can access the Web Admin Console using http://YOUR_IP_ADDRESS:7080.
You will be redirected to the login page. Use the credentials that we created earlier to login to the panel. Using this panel you will be able to set up hosts, manage listeners for your server and many more. We will be creating virtual hosts in next part.