CI/CD with AWS EC2 (Best for Full Stack Projects or Laravel API)

This option is for custom deployments — you have to configure CI/CD manually using GitHub Actions.

Vivek Rastogi

7/29/20251 min read

🔧 Step-by-Step Guide

🟢 Step 1: Prepare EC2 Server (One-Time)
  • Launch an EC2 Ubuntu instance

  • Install Node.js, Git, PM2 (or Laravel + PHP + MySQL stack)

  • Clone your GitHub repo on the server

  • sudo apt update

  • sudo apt install nodejs npm git

  • git clone https://github.com/yourusername/your-portfolio.git

  • cd your-portfolio

  • npm install

  • npm run build

  • npm start # or use pm2 start npm --name "portfolio" -- start

🟢 Step 2: Create a .env File (if needed)

NEXT_PUBLIC_SITE_NAME="Vivek Rastogi"

🟢Step 3: Set up GitHub Actions Workflow

In your GitHub repo, create:

  • mkdir -p .github/workflows

Create deploy.yml inside that folder:

Step 4: Add GitHub Secrets

In GitHub:

  • Go to your repo → Settings → Secrets → Actions

  • Add:

    • EC2_HOST = your EC2 public IP

    • EC2_USER = usually ubuntu

    • EC2_KEY = your private SSH key (not .pem, convert to plain text)