Header

Complete Guide: Deploying Gemini Search with DeployHQ

AI, Node, Open Source, and Tutorials

Post Image

Table of Contents

  1. Prerequisites
  2. Server Setup
  3. DeployHQ Configuration
  4. Deployment Process
  5. Post-Deployment Steps

1. Prerequisites

2. Server Setup

2.1 Initial Server Configuration

First, SSH into your server:

ssh root@your_server_ip

Update the system:

apt update && apt upgrade -y

2.2 Create a Non-Root User

# Create new user
adduser deploy

# Add user to sudo group
usermod -aG sudo deploy

# Switch to new user
su - deploy

2.3 Install Required Software

Install Node.js and npm:

# Install Node.js repository
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

# Install Node.js and npm
sudo apt install -y nodejs

# Verify installation
node --version
npm --version

Install Nginx: bash sudo apt install nginx -y

2.4 Configure Nginx

Create a new Nginx configuration:

sudo nano /etc/nginx/sites-available/gemini-search

Add the following configuration:

server {
    listen 80;
    server_name your_domain.com;  # Or your server IP

    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_cache_bypass $http_upgrade;
    }
}

Enable the site:

sudo ln -s /etc/nginx/sites-available/gemini-search /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

2.5 Install PM2 for Process Management

sudo npm install -g pm2

2.6 Set Up Project Directory

# Create application directory
sudo mkdir -p /var/www/gemini-search
sudo chown deploy:deploy /var/www/gemini-search

3. DeployHQ Configuration

3.1 Setting Up Your DeployHQ Account

  1. Sign up at deployhq.com
  2. Create a new project

3.2 Repository Configuration

  1. Connect to GitHub
  2. Select the Gemini Search repository
  3. Configure branch settings:
Repository: ammaarreshi/Gemini-Search
Branch: main

3.3 Server Configuration in DeployHQ

  1. Go to "Servers" → "Add Server"
  2. Configure SFTP connection:
Protocol: SFTP
Hostname: your_server_ip
Username: deploy
Authentication: SSH Key
Deploy Path: /var/www/gemini-search

3.4 Deployment Configuration

Create a deployment configuration file:

# Build Pipeline
build:
  - npm install
  - npm run build

# Config File
environment:
  - GOOGLE_API_KEY=${GOOGLE_API_KEY}

# SSH Commands
post_deploy:
  - pm2 restart gemini-search || pm2 start npm --name "gemini-search" -- start

4. Deployment Process

4.1 Initial Deployment

  1. In DeployHQ dashboard, click "Deploy"
  2. Select the main branch
  3. Start deployment

4.2 Set Up PM2 Startup Script

On your server:

pm2 startup systemd
sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u deploy --hp /home/deploy
pm2 save

5. Post-Deployment Steps

5.1 SSL Configuration (Optional)

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

# Obtain SSL certificate
sudo certbot --nginx -d your_domain.com

5.2 Verify Deployment

1- Check application status:

pm2 status

2- View logs:

pm2 logs gemini-search

3- Test the application:

  • Open your browser
  • Visit http://your_domain.com or http://your_server_ip
  • Test the search functionality

5.3 Monitoring Setup

Set up basic monitoring:

# Monitor memory usage
pm2 monit

# Set up PM2 monitoring
pm2 plus

5.4 Backup Configuration

Create a backup script:

#!/bin/bash
backup_dir="/backup/gemini-search"
date=$(date +%Y%m%d)

# Create backup directory
mkdir -p $backup_dir

# Backup application files
tar -czf $backup_dir/app_$date.tar.gz /var/www/gemini-search

# Backup nginx configuration
cp /etc/nginx/sites-available/gemini-search $backup_dir/nginx_$date.conf

Troubleshooting

Common Issues and Solutions

1- Application Not Starting

# Check PM2 logs
pm2 logs gemini-search

# Verify environment variables
nano /var/www/gemini-search/.env

2- Nginx Issues

# Check Nginx status
sudo systemctl status nginx

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

3- Permission Issues

# Fix permissions
sudo chown -R deploy:deploy /var/www/gemini-search

Maintenance Tasks

Regular Updates

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

# Update Node.js packages
cd /var/www/gemini-search
npm update

# Restart application
pm2 restart gemini-search

Monitoring Commands

# Check application status
pm2 status

# Monitor resources
pm2 monit

# View logs
pm2 logs gemini-search

This comprehensive guide should give you everything needed to set up and maintain your Gemini Search deployment. Remember to regularly check for updates and monitor your application's performance.

A little bit about the author

Facundo | CTO | DeployHQ | Continuous Delivery & Software Engineering Leadership - As CTO at DeployHQ, Facundo leads the software engineering team, driving innovation in continuous delivery. Outside of work, he enjoys cycling and nature, accompanied by Bono 🐶.

Tree

Proudly powered by Katapult. Running on 100% renewable energy.