Step-by-Step Guide to Installing Strapi with PostgreSQL on AWS

Back-EndLinuxTutorials
Step-by-Step Guide to Installing Strapi with PostgreSQL on AWS

November 21, 2024

If you're looking to leverage AWS's robust cloud infrastructure for deploying Strapi with PostgreSQL, this guide will walk you through the entire process. From setting up your database to deploying Strapi on EC2, we've got you covered.


1. Initial Preparations

Before diving in, ensure you have the following:


2. Set Up PostgreSQL on AWS RDS

Create an RDS Instance

Configure Security Groups


3. Launch an EC2 Instance

Set Up the Instance

Connect to EC2


4. Install Dependencies

Update your EC2 instance and install required software:

sudo apt update && sudo apt upgrade -y
sudo apt install -y git
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs
npm install -g yarn # optional

5. Deploy Strapi

Create a Strapi Project

npx create-strapi-app my-project --quickstart
cd my-project
npm install pg

Configure PostgreSQL

Edit config/database.js:

module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: env('DATABASE_HOST', 'your-rds-endpoint'),
      port: env.int('DATABASE_PORT', 5432),
      database: env('DATABASE_NAME', 'your-database-name'),
      user: env('DATABASE_USERNAME', 'your-username'),
      password: env('DATABASE_PASSWORD', 'your-password'),
      ssl: env.bool('DATABASE_SSL', false),
    },
    debug: false,
  },
});

Run Strapi

npm run develop

Access the admin panel at http://your-public-ip:1337/admin.


6. Set Up Nginx (Optional)

Install Nginx:

sudo apt install -y nginx

Configure a reverse proxy for Strapi on port 1337.


7. Enable SSL (Optional)

Install Certbot:

sudo apt install -y certbot python3-certbot-nginx

Run:

sudo certbot --nginx -d your-domain.com -d www.your-domain.com

Conclusion

By following this guide, you can successfully deploy Strapi with PostgreSQL on AWS, leveraging AWS’s scalability and reliability. For production environments, consider adding monitoring and auto-scaling features to optimize performance further.