Install on AWS EC2 Ubuntu Server

Prerequisite: Make sure you've completed the How to push to GitHub before proceeding with How to install on AWS EC2.

📹 Video Tutorial

Watch this comprehensive video guide for step-by-step AWS EC2 setup instructions:

Watch on YouTube if the video doesn't load above

🎥 Video Guide: This tutorial covers the complete AWS EC2 setup process including server configuration, environment setup, and deployment steps. Follow along for the easiest installation experience!
Important Note: This video demonstrates the standard AWS EC2 installation process for any Node.js project. It does not show the specific installation steps for this LogoAIpro project. Please follow the written instructions below for project-specific setup requirements and configurations.

Requirements

Estimated Cost: t2.micro instance (free tier) can run this application. For production, consider t3.small or larger.

Step 1: Create AWS Account and EC2 Instance

1.1 Sign up for AWS

  1. Go to aws.amazon.com and click "Create an AWS Account"
  2. Fill in your account details and verify your email/phone
  3. Add a payment method (required even for free tier)
  4. Choose "Basic Support" (free tier includes this)

1.2 Launch EC2 Instance

  1. Sign in to AWS Console and navigate to EC2 service
  2. Click "Launch Instance"
  3. Choose "Ubuntu Server 24.04 LTS" (free tier eligible)
  4. Select "t2.micro" instance type (free tier)
  5. Create or select a key pair for SSH access
  6. Configure security group with these rules:
    Type: SSH, Protocol: TCP, Port: 22, Source: My IP
    Type: HTTP, Protocol: TCP, Port: 80, Source: 0.0.0.0/0
    Type: HTTPS, Protocol: TCP, Port: 443, Source: 0.0.0.0/0
    Type: Custom TCP, Protocol: TCP, Port: 3000, Source: 0.0.0.0/0

    Note: If using AWS EC2 Instance Connect, you don't need to open SSH port 22 to your IP. EC2 Instance Connect handles authentication automatically.

  7. Launch the instance and wait for it to be "running"

Step 2: Connect to Your EC2 Instance

2.1 Using AWS EC2 Instance Connect (Recommended)

  1. In EC2 Console, select your running instance
  2. Click the "Connect" button at the top
  3. Select "EC2 Instance Connect" tab
  4. Click "Connect" - this will open a browser-based terminal
  5. You're now connected to your instance!
AWS EC2 Instance Connect: This method doesn't require downloading key files or configuring SSH clients. It works directly in your browser and is more secure.

2.2 Alternative: AWS Systems Manager Session Manager

  1. In EC2 Console, select your instance
  2. Click the "Connect" button
  3. Select "Session Manager" tab
  4. Click "Connect" to open a browser-based terminal
Note: Session Manager requires the SSM agent to be installed and running on your instance. This is pre-installed on Amazon Linux 2 and Ubuntu 18.04+ AMIs.

2.3 Traditional SSH (If needed)

If you prefer traditional SSH or need it for specific use cases:

# Make your key file secure
chmod 400 /path/to/your-key.pem

# Connect to your instance
ssh -i /path/to/your-key.pem ubuntu@YOUR_PUBLIC_IP

# Example:
ssh -i ~/Downloads/my-key.pem ubuntu@3.15.123.45

Step 3: Install Required Software

3.1 Update System

# Update package list and upgrade system
sudo apt update && sudo apt upgrade -y

# Install essential packages
sudo apt install -y curl wget git unzip software-properties-common

3.2 Install Node.js 18+

# Install Node.js using NodeSource repository
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# Verify installation
node --version  # Should show v18.x.x or higher
npm --version

3.3 Install PM2 (Process Manager)

# Install PM2 globally
sudo npm install -g pm2

# Configure PM2 to start on boot
pm2 startup
# Follow the instructions shown by the command

3.4 Install Nginx (Reverse Proxy)

# Install Nginx
sudo apt install -y nginx

# Start and enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx

# Check status
sudo systemctl status nginx

Step 4: Deploy the Application

4.1 Clone Your Repository

# Create application directory
sudo mkdir -p /var/www
cd /var/www

# Clone your repository (replace with your actual repo URL)
sudo git clone https://github.com/yourusername/logo-ai-pro.git logo-ai-pro
sudo chown -R ubuntu:ubuntu logo-ai-pro
cd logo-ai-pro

4.2 Install Dependencies

# Install project dependencies
npm install

# Build the application
npm run build

4.3 Configure Environment Variables

# Create environment file
nano .env.local

# Add all required environment variables (see env-setup.html)
# MongoDB Connection (required)
DATABASE_URL=mongodb+srv://username:password@cluster.mongodb.net/logo-ai-pro

# Clerk Authentication (required)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
CLERK_WEBHOOK_SECRET=whsec_...

# Nebius AI (required)
NEBIUS_API_KEY=your-nebius-api-key

# Stripe Configuration (required)
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...

# Upstash Redis (required)
UPSTASH_REDIS_REST_URL=https://...
UPSTASH_REDIS_REST_TOKEN=...

# App URL
NEXT_PUBLIC_APP_URL=http://YOUR_PUBLIC_IP:3000

# Optional: Helicone (for observability)
HELICONE_API_KEY=your-helicone-key

# Optional: Umami (for analytics)
UMAMI_WEBSITE_ID=your-umami-id

Step 5: Configure Nginx

5.1 Create Nginx Configuration

# Create Nginx configuration
sudo nano /etc/nginx/sites-available/default

# Add the following configuration:
server {
    listen 80;
    server_name YOUR_PUBLIC_IP;  # Replace with your domain if you have one

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}

5.2 Enable the Site

# Enable the site
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/

# Remove default site
sudo rm /etc/nginx/sites-enabled/default

# Test Nginx configuration
sudo nginx -t

# Restart Nginx
sudo systemctl restart nginx

Step 6: Start the Application

6.1 Start with PM2

# Start the application with PM2
pm2 start npm --name "logo-ai-pro" -- start

# Save PM2 configuration
pm2 save

# Check status
pm2 status
pm2 logs logo-ai-pro

Step 7: Configure SSL (Optional but Recommended)

7.1 Install Certbot

# Install Certbot
sudo apt install -y certbot python3-certbot-nginx

# Get SSL certificate (replace with your domain)
sudo certbot --nginx -d yourdomain.com

# Test auto-renewal
sudo certbot renew --dry-run

Step 8: Configure Firewall

# Configure UFW firewall
sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw --force enable

# Check status
sudo ufw status

Step 9: Update Webhook URLs

  1. Go to Stripe Dashboard → Webhooks
  2. Update your webhook endpoint URL to: https://YOUR_DOMAIN/api/webhooks/stripe
  3. Go to Clerk Dashboard → Webhooks
  4. Update your webhook endpoint URL to: https://YOUR_DOMAIN/api/webhooks/clerk
  5. Test the webhooks using the test endpoints

Step 10: Verify Installation

# Check if the application is running
curl http://localhost:3000/api/db-health

# Check Nginx status
sudo systemctl status nginx

# Check PM2 status
pm2 status

# View application logs
pm2 logs logo-ai-pro

Useful Commands

Application Management

# Restart application
pm2 restart logo-ai-pro

# Stop application
pm2 stop logo-ai-pro

# View logs
pm2 logs logo-ai-pro

# Monitor resources
pm2 monit

Nginx Management

# Restart Nginx
sudo systemctl restart nginx

# Reload Nginx configuration
sudo systemctl reload nginx

# Check Nginx status
sudo systemctl status nginx

System Updates

# Update system packages
sudo apt update && sudo apt upgrade -y

# Update application
cd /var/www/logo-ai-pro
git pull origin main
npm install
npm run build
pm2 restart logo-ai-pro

Troubleshooting

Common Issues

Log Locations

# Application logs
pm2 logs logo-ai-pro

# Nginx logs
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log

# System logs
sudo journalctl -u nginx
sudo journalctl -u pm2-ubuntu
Security Note: For production use, consider setting up a proper domain name, configuring a WAF, and implementing additional security measures like fail2ban.

Cost Optimization