• Mail us
  • Book a Meeting
  • Call us
  • Chat with us

CMS

How to Deploy Strapi CMS on AWS EC2


Introduction

Strapi, an open-source headless CMS, is a great choice for deployment on Amazon Web Services (AWS), offering scalability and flexibility. This guide walks you through downloading and setting up Strapi on AWS using EC2, with optional integration of RDS for the database and S3 for file storage.

Why Deploy on AWS?

AWS provides robust features for hosting Strapi:

  • Scalability: Adjust resources with EC2 instance types.

  • Reliability: High uptime with AWS’s global infrastructure.

  • Storage: Use S3 for scalable file uploads.

  • Database: RDS supports PostgreSQL and MySQL for Strapi.

Prerequisites

Prepare these before starting:

  • AWS Account: Sign up at aws.amazon.com if needed.

  • Node.js: Install version 18+ locally for initial setup.

  • Git: Verify with git --version.

  • SSH Client: Use PuTTY or an SSH tool for EC2 access.

  • Database: Set up RDS (PostgreSQL or MySQL) or use a local database initially.

Step-by-Step Guide to Download and Deploy

Follow these steps to set up Strapi on AWS:

 

Step 1: Launch an EC2 Instance

  • Log in to the AWS Console and search for EC2.
  • Click “Launch Instance,” choose Ubuntu Server 22.04 LTS (HVM), and select t2.small (minimum 2GB RAM for Strapi).
  • Create a key pair (e.g., strapi-key.pem), download it, and set permissions with chmod 400 strapi-key.pem
  • Configure a security group to allow ports 22 (SSH), 80 (HTTP), and 1337 (Strapi default).

 

Step 2: Connect to the Instance

  • Use SSH to connect: ssh -i strapi-key.pem ubuntu@your-ec2-public-ip
  • Update the package list with sudo apt update && sudo apt upgrade -y

 

Step 3: Install Node.js and Dependencies

  • Install Node.js with curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - followed by sudo apt install -y nodejs
  • Verify with node -v (should show v18.x).
  • Install Git with sudo apt install -y git

 

Step 4: Install Strapi

  • Navigate to your home directory with cd ~ .
  • Run npx create-strapi-app@latest strapi-project --quickstart to create a project.
  • Follow the prompt to set up the admin user.

 

Step 5: Configure the Database

  • Set up RDS (e.g., PostgreSQL) in the AWS Console.
  • Edit config/database.js with your RDS endpoint, database name, username, and password.
  • Example: { "defaultConnection": "default", "connections": { "default": { "connector": "bookshelf", "settings": { "client": "postgres", "host": "your-rds-endpoint", "port": 5432, "database": "strapi", "username": "your-username", "password": "your-password" }, "options": {} } } }
  • Install the database client (e.g., npm install pg) if needed.

 

Step 6: Build and Start Strapi

  • Build the admin panel with npm run build.
  • Start the server with npm run start or use PM2 for production with npm install -g pm2 and pm2 start npm -- start.
  • Access Strapi at http://your-ec2-public-ip:1337.

 

Step 7: Set Up S3 for File Uploads (Optional)

  • Create an S3 bucket in the AWS Console.
  • Install the S3 plugin with npm install @strapi/provider-upload-aws-s3.
  • Configure it in plugins.js with your access key, secret key, region, and bucket name (see Strapi docs).

Troubleshooting Common Issues

Resolve these potential problems:

  • SSH Connection Fails: Check your security group and key pair permissions.

  • Strapi Won’t Start: Verify Node.js version and database connectivity.

  • S3 Upload Errors: Ensure IAM permissions and bucket policy are correctly set.

  • Memory Issues: Upgrade to a larger instance (e.g., t2.medium) if Strapi crashes.

Tips for a Successful AWS Deployment

Enhance your setup with these ideas:

  • Use PM2: Manage Strapi as a service with pm2 save for auto-restart.

  • Monitor with CloudWatch: Install the CloudWatch agent to track performance.

  • Backup RDS: Set up automated snapshots in the RDS console.

  • Secure Access: Use HTTPS with an Elastic Load Balancer.

Advanced Configuration

Take your AWS deployment further:

  • Custom Domains: Map a domain with Route 53.

  • Auto-Scaling: Use Auto Scaling Groups with EC2.

  • SSL: Enable HTTPS with AWS Certificate Manager.

Conclusion

Deploying Strapi on AWS with EC2, RDS, and S3 provides a scalable and reliable CMS solution. By launching an instance, installing Strapi, and configuring your database and storage, you can set up a production-ready site. With monitoring and advanced options, your Strapi deployment will thrive on AWS.

 

Ready to transform your business with our technology solutions? Contact Us   

Share

facebook
LinkedIn
Twitter
Mail
CMS

Related Center Of Excellence