Skip to content

Setting up the remote server and installing prerequisites

Omolara Adeboye edited this page Jul 20, 2024 · 12 revisions

Introduction

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.

Server Setup

  1. 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_ip

Replace username with your server's username and your_server_ip with the server's IP address.

  1. 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
  1. 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
  1. 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 -y

Verify the installation:

python3 --version
pip3 --version

PostgreSQL Setup

  1. 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-contrib
  • Start and enable the postgresql service
sudo systemctl start postgresql
sudo systemctl enable postgresql
  • Check the status
sudo systemctl status postgresql
  1. 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> --pwprompt

This 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:

\q

Clone this wiki locally