This guide will take you step by step on how to successfully host your Django Application on Cyberpanel running Almalinux OS.
Requirements: #
Accessibility : Root Access to the server.
Operating System(OS): Almalinux OS
Application: Django
Step 1: Installing Python #
If you’re okay with default version of Python installation on Almalinux, you can skip to step Step 3;
By default, Almalinux 8 comes with python version 3.6. However, this version may not be suitable to run our application. In this case, we need to easily install another version of Python say 3.7, 3.8, 3.9, 3.10, 3.11, 3.12,
as needed.
In this guide, I’ll show you how to Install our own version.
We shall install python 3.8
in our case. (Feel free to install your preferred version, all steps are the same)
We shall be using pyenv
– > A package to install and manage multiple python versions. See more
https://github.com/pyenv/pyenv
Installing Required packages . #
yum -y install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel mysql-devel pkgconfig libpq-devel

Install Development packages. #
yum -y groupinstall "Development Tools"

Step 2: Download and Install pyenv #
Download and Install pyenv #
curl https://pyenv.run | bash

Enable pyenv #
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Confirm pyenv is working;.
pyenv
You should see output similar to one below.

Installing Python 3.8 using pyenv
First type the command below to see available versions that can be installed using pyenv.
pyenv install --list
You should see output similar to one below. The output is very long , so just scroll until you find the version you want.

The below image shows our python 3 versions. You can choose any

To install version 3.8.20, type the command below. Since I had installed, I will not re-install.
pyenv install 3.8.20

Now you can make python 3.8.20 available globally by typing.
pyenv global 3.8.20
(Replace with your installed version)

Now all is done as far as python installation is concerned.
Step 3: Installing lswgi #
Download from Litespeed. At time of writing, lsapi-2.1 is the latest version.
To check see link below.
https://www.litespeedtech.com/open-source/litespeed-sapi/download
curl -O https://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-2.1.tgz
Extract the archive
tar xf wsgi-lsapi-2.1.tgz
Navigate to the extracted directory
cd wsgi-lsapi-2.1/
Build wsgi with the new python version.
python3 ./configure.py
make
Copy the package to the fcgi-bin directory.
cp lswsgi /usr/local/lsws/fcgi-bin/
Confirm it is there
cd /usr/local/lsws/fcgi-bin/
ls

Step 4: Create a website on Cyberpanel. #
In this guide, I’ll be using a sub-domain
https://superdjango.lintsawa.com

Website created and now loads default cyberpanel page.

Upload your website files to the public_html folder and extract.

Navigate via SSH to cd /home/yourdomain.com/
Where necessary, replace with your domain name.
Create and activate virtual env
python3 -m venv /home/superdjango.lintsawa.com/myenv/
Activate.
source /home/superdjango.lintsawa.com/myenv/bin/activate

Navigate to your projects directory where you have your requirements.txt file

Install your project dependencies.

Migrate your database

Create your superuser.

Collect the static files
python manage.py collectstatic

Now for the app to load,
Go back to Cyberpanel dashboard > Websites > List Website > Manage > Configurations >vHost and Add the context below to vHost section of your domain.
Do NOT delete the existing details. Scroll to the bottom and add the context
Add Context.
Replace where necessary
Adjust your Location, startupFile and env
=================
context / {
type appserver
location /home/superdjango.lintsawa.com/public_html/portfolio-website-main
binPath /usr/local/lsws/fcgi-bin/lswsgi
appType wsgi
startupFile Portfolio/wsgi.py
envType 1
env LS_PYTHONBIN=/home/superdjango.lintsawa.com/myenv/bin/python3
}
Screenshot.


Restart openlitespeed.
/usr/local/lsws/bin/lswsctrl restart

Reload your website.
You should your site working well as expected.

Confirm you can also access the admin section.

Congrats. You have successfully deployed your django website to Cyberpanel with Openlitespeed.
In case of Errors use command below to view the error messages for troubleshooting.
==========
tail -f /usr/local/lsws/logs/stderr.log
Happy Hosting!!!