-
Notifications
You must be signed in to change notification settings - Fork 0
Setting up the remote server and installing prerequisites
To ensure our application runs smoothly, we need to set up a remote server with all the necessary prerequisites. This includes installing Git, Python, pip, and PostgreSQL. This guide walks you through each step, ensuring your server is ready for deployment.
-
Accessing the Remote Server
To access the remote server, you will need SSH credentials. Use the following command to connect to your server:
ssh username@your_server_ipReplace username with your server's username and your_server_ip with the server's IP address.
-
Updating the System
Before installing any software, it's good practice to update the system packages to their latest versions:
sudo apt update && sudo apt upgrade -y-
Installing Git
Git is essential for cloning the repository and managing code. Install Git and verify the version installed by using the following commands:
sudo apt install git -y
git --version-
Installing Python and pip
Our application is built using Python, so we need to install Python and pip (Python's package installer):
sudo apt install python3 python3-pip -yVerify the installation:
python3 --version
pip3 --version- Installing PostgreSQL PostgreSQL is our database of choice. Install PostgreSQL using the following commands:
Add the PostgreSQL APT repository:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'Import the repository signing key:
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -Update the package lists and install the latest stable version of PostgreSQL:
sudo apt-get update
sudo apt-get install postgresql postgresql-contribStart and enable the postgresql service:
sudo systemctl start postgresql
sudo systemctl enable postgresqlCheck the status:
sudo systemctl status postgresql- Configuring PostgreSQL
Switch to the PostgreSQL user to configure the database:
sudo -i -u postgres Setup Databases and Users
Create a new PostgreSQL user and databases for the application:
- Create a new user:
createuser <user-name> --pwpromptThis will prompt for the password of the new user. Enter a secure password following best practices. Replace in the command with your desired user name.
- Create a new database:
createdb <new-db>Create three databases for the dev, staging and prod respectively by replacing with the appropriate names.
e.g
python_dev_db, python_staging_db, python_prod_db
- Grant all privileges on the database to the new user:
GRANT ALL PRIVILEGES ON DATABASE <new-db> TO <user-name>;Assuming username is pythonguru
GRANT ALL PRIVILEGES ON DATABASE python_dev_db TO pythonguru;Repeat this for staging and prod databases respectively.
Exit the PostgreSQL prompt:
\qNginx is a powerful web server that will be used to serve our application and handle requests. Install Nginx using the following command:
sudo apt install nginx -yVerify the installation:
sudo apt install nginx -yStart and enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginxRabbitMQ is a message broker that Celery uses to handle asynchronous tasks Install RabbitMQ using the following commands:
sudo apt install rabbitmq-server -y
Verify the installation:
sudo systemctl status rabbitmq-server
Start and enable RabbitMQ:
sudo systemctl start rabbitmq-server
sudo systemctl enable rabbitmq-serverInstall Celery using pip:
pip install -U celery
- The repository should be cloned into the server using the following command:
git clone <repository-url>Replace the with the github repository url of the app.
git clone https://github.com/hngprojects/hng_boilerplate_python_fastapi_web.git- Make copies of the directory renaming them to dev, staging and prod respectively.
cp -r /path/to/your/application/yourrepository/* /path/to/your/application/dev/
cp -r /path/to/your/application/yourrepository/* /path/to/your/application/staging/
cp -r /path/to/your/application/yourrepository/* /path/to/your/application/prod/You alternatively, within the location of application directory, first, rename the directory hng_boilerplate_python_fastapi_web to a manageable name.
mv hng_boilerplate_python_fastapi_web source_codecp -r source_code source_dev_code
cp -r source_code source_staging_code
cp -r source_code source_prod_codeThese application directories represent the dev, staging and prod environments repectively.
- Home
- CI CD Pipeline Configuration for the Python Application
- Deployment with Systemd
- NGINX Reverse Proxy Setup and SSL Configuration
- Setting up the remote server and installing prerequisites
(Content not available in the provided HTML)
(Content not available in the provided HTML)