Deploying Django with OpenLiteSpeed (Part 5)

| |

We have uploaded our project in the last part of tutorial. We’ll now create virtual environment and use the requirements.txt for installation of package. Finally we will have our project LIVE after few more configurations.

Log on to the VPS using terminal before proceeding.

Create Virtual Environment

First let’s install virtualenv package in our server. virtualenv is a tool to create isolated Python environments.

$ pip3 install virtualenv

We’ll create virtual environment inside the virtual host folder(/usr/local/lsws/social here). Run following command:

$ virtualenv /usr/local/lsws/social

And activate the environment using :

$ source /usr/local/lsws/social/bin/activate

Check if python loaded from virtual environment

$ which python

Install Packages from requirements.txt

Navigate to root directory of the project

$ cd /usr/local/lsws/social/public

Now we’ll install all the packages in the requirements.txt file. Run this command in terminal.

$ pip3 install -r requirements.txt

Finally we need to install psycopg2 library as adaptor between Python and Postgesql Database.

$ pip3 install psycopg2

Final Touch

We are almost finished the setup part and our site will be Live soon. Now lets edit the Context configuration. Open the Web Admin Panel in browser and Navigate to Virtual Hosts > “Your Virtual Host” > Context > “Your context” . Click on “pen” icon to edit the configuration.

We had set the Startup File to “wsgi.py”. Change it to point the location of wsgi.py file of Django project. wsgi.py file is located in same folder as settings.py by default. This path is relative to application root directory. Also in Environment we’ll add some variables like PYTHONPATH for setting up with virtual environment.

Startup File : social/wsgi.py
Environment:
PYTHONPATH=/usr/local/lsws/social/lib/python3.8:/usr/local/lsws/social/public
LS_PYTHONBIN=/usr/local/lsws/social/bin/python

Collect static files

$ python manage.py collectstatic

And the Final step, Create admin super user

$ python manage.py migrate
$ python manage.py createsuperuser

Great! you are all set up and your site is already LIVE. Visit http://YOUR_DOMAIN in the browser

Previous

Deploying Django with OpenLiteSpeed (Part 4)

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

[…] Alright!! we are ready for finals steps. We will install the required packages and finally completely deploy django with openlitespeed in next article( Part 5 ). […]

1
0
Would love your thoughts, please comment.x
()
x