Deploying Django with OpenLiteSpeed (Part 4)

| |

I’m glad you completed all the steps successfully. Now we’ll upload our project to document root(/usr/local/lsws/social/public) using filezilla and finally install Postgres database backend in Ubuntu 20.04. We’ll configure the database to match our Django app configuration.Generate requirements.txt

From Django to all other small and large package installed on your development server needs to be installed in VPS for your project to run. Listing manually and installing one by one is not easy task also not clever way. We have a command to generate all the package used in our environment with their versions. Then you can use this list to install all packages in VPS with single command.

Navigate to project directory at your computer using the terminal. Now start the virtual environment that you used during development. Run following command to create a requirements.txt file with all package list.

$ pip freeze > requirements.txt

The file will be created in root directory of project.

SFTP using Filezilla Client

Open filezilla client and navigate to project folder in your computer. Ubuntu server comes with sftp installed so we won’t need to do any extra setup in the server for FTP for now.

In top bar enter the ip address of the VPS in Host field, put username that you used to login VPS in ssh (generally root), and password of the root. If you dont have password then you can reset using passwd command in the terminal. For SFTP you need to select Port as 22 then click Quickconnect button. After successful connection the root directories will be listed in the Right part of the windows.

Navigate to Document root of virtual host (/usr/local/lsws/$VH_NAME/public)for me /usr/local/lsws/social/public . Select the project files and folder in left pane then drag and drop to right pane. The upload will start and will take few minutes. After completion you can close the Filezilla, and open the terminal and connect to the server.

Install and Configure Postgres

Our first step will be install database software and the associated libraries required to interact with them.

The following apt commands will get you the packages you need:

$ sudo apt-get update
$ sudo apt-get install libpq-dev postgresql postgresql-contrib

During the Postgres installation, an operating system user named postgres was created to correspond to the postgres PostgreSQL administrative user. We need to change to this user to perform administrative tasks:

sudo su - postgres

You should now be in a shell session for the postgres user. Log into a Postgres session by typing:

psql

First, we will create a database for our Django project.

Remember the credentials we set here must match with the one in settings .py file we set earlier.

Each project should have its own isolated database for security reasons. We will call our database myproject in this guide, but it’s always better to select something more descriptive:

CREATE DATABASE myproject;

Remember to end all commands at an SQL prompt with a semicolon.

Next, we will create a database user which we will use to connect to and interact with the database. Set the password to something strong and secure:

CREATE USER myprojectuser WITH PASSWORD 'password';

Afterwards, we’ll modify a few of the connection parameters for the user we just created. This will speed up database operations so that the correct values do not have to be queried and set each time a connection is established.

ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myprojectuser SET timezone TO 'UTC';

Now, all we need to do is give our database user access rights to the database we created:

GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;

Exit the SQL prompt to get back to the postgres user’s shell session:

\q

Exit out of the postgres user’s shell session to get back to your regular user’s shell session:

exit

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 ).

Previous

Deploying Django with OpenLiteSpeed (Part 3)

Deploying Django with OpenLiteSpeed (Part 5)

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

[…] Save the settings.py file. Now you are a step behind for deployment of Django app. In Next Part we’ll upload our project using filezilla client, and install Postgres data base a… […]

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