Run commands
sudo apt-get update
sudo apt-get install python3-pip python3-dev nginx
sudo apt-get install libpq-dev
sudo apt-get install libssl-dev
sudo apt-get install postgresql
sudo su postgres
. Switches to postgres userpsql
in postgres user shellCREATE USER <username> WITH SUPERUSER PASSWORD '<password>'
. Enter user username and password fot the DB. For ex: CREATE USER agmt WITH SUPERUSER PASSWORD 'pass&14'
createdb <db_name>
gedit .bashrc
from home directory)bashrc
file.
export AGMT_SENDINBLUE_KEY="<send_in_blue_key>"
export AGMT_HS256_SECRET="<jwt_token_key>"
export AGMT_POSTGRES_HOST="localhost"
export AGMT_POSTGRES_PORT="5432"
export AGMT_POSTGRES_USER="<db_user>"
export AGMT_POSTGRES_PASSWORD="<db_password>"
export AGMT_POSTGRES_DATABASE="<db_name>"
sudo pip3 install virtualenv
virtualenv myprojectenv
. You can enter your custom name instead of myprojectenv
.Run Command source myprojectenv/bin/activate
. Activate the virtual environment before installing dependencies.
requirements.txt
file.pip3 install -r requirements.txt
db.sql
file. (Inside agmt
folder)psql -d <db_name> -f ./db.sql
gunicorn main:app
inside the project folder containing the main.py
file.amt
, python virtual environment name is venv3
, the project folder name is vachan-api
and the main.py
file is in vachan-api/agmt/
folder then the config files will be like:vachanconfig
Copy and edit the files according to the project credentials and directories and save file as gunicorn.service
. You could use your custom name for the file.
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=amt
Group=amt
WorkingDirectory=/home/amt/vachan-api/agmt
Environment="AGMT_SENDINBLUE_KEY=<send_in_blue_key>"
Environment="AGMT_HS256_SECRET=<jwt_algorithm_key>"
Environment="AGMT_POSTGRES_USER=<db_user_name>"
Environment="AGMT_POSTGRES_PASSWORD=<db_password>"
Environment="AGMT_POSTGRES_DATABASE=<db_name>"
Environment="AGMT_HOST_API_URL=<api_url>"
Environment="AGMT_HOST_UI_URL=<UI_url>"
ExecStart=/home/amt/venv3/bin/gunicorn --workers 3 --bind unix:/home/amt/vachan-api/agmt/agmt.sock main:app --timeout=18000
[Install]
WantedBy=multi-user.target
systemd
foldergunicorn.service
file in systemd
folder
sudo ln -s /home/amt/vachan-api/vachnaconfig/gunicorn.service /etc/systemd/system/
sudo systemctl start gunicorn.service
sudo systemctl enable gunicorn.service
nginx.conf
. You could use your custom name for the file.For enabling ssl refer online documentation.
server {
listen 80;
server_name <server_domain_name>;
location / {
include proxy_params;
proxy_pass http://unix:/home/amt/vachan-api/agmt/agmt.sock;
proxy_read_timeout 18000;
proxy_connect_timeout 18000;
proxy_send_timeout 18000;
send_timeout 18000;
}
}
sites-enabled
nginx.conf
file has to be linked first to sites-available
and from sites-available
to sites-enabled
.sudo ln -s /home/amt/vachan-api/vachnaconfig/nginx.conf /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/nginx.conf /etc/nginx/sites-enabled
sudo nginx -t
to check for syntax errors in the nginx.conf
file.sudo systemctl restart nginx