# DigitalOcean Droplet Deployment Guide for GOCO Technology
**Target Domain**: `https://www.gocotechnology.com`

This guide walks you step-by-step through setting up a DigitalOcean Droplet, configuring LEMP (Linux, Nginx, MySQL, PHP 8.2+), installing Let's Encrypt SSL, and launching your Laravel site.

---

## Step 1: Create & Launch DigitalOcean Droplet

1. Log into your [DigitalOcean Dashboard](https://cloud.digitalocean.com).
2. Click **Create** -> **Droplets**.
3. **Choose Image**: Ubuntu 22.04 LTS (or Ubuntu 24.04 LTS).
4. **Choose Size**: Basic Plan ($6/mo - $12/mo with 1GB to 2GB RAM is recommended).
5. **Authentication**: Select **SSH Key** (Recommended) or Root Password.
6. **Finalize**: Choose a region closest to your primary target audience (e.g. Bangalore, Singapore, or Frankfurt) and set Hostname to `gocotechnology-server`.
7. Click **Create Droplet**. Note the public **IP address** assigned to your droplet.

---

## Step 2: Configure Domain DNS (Cloudflare / Namecheap / DigitalOcean)

Point your domain to your Droplet IP address by adding the following `A` records in your DNS management provider:

| Type | Host / Name | Value / Points To | TTL |
| :--- | :--- | :--- | :--- |
| **A** | `@` | `YOUR_DROPLET_IP` | Automatic / 300 |
| **A** | `www` | `YOUR_DROPLET_IP` | Automatic / 300 |

*Note: Allow 5–15 minutes for DNS propagation.*

---

## Step 3: Server Setup & Dependencies Installation

SSH into your Droplet as root:
```bash
ssh root@YOUR_DROPLET_IP
```

Update packages and install Nginx, MySQL, PHP 8.2, Git, Unzip, and Certbot:
```bash
sudo apt update && sudo apt upgrade -y

# Install Nginx, MySQL, and PHP 8.2 dependencies
sudo apt install -y nginx mysql-server composer git unzip curl \
  php8.2-fpm php8.2-cli php8.2-mysql php8.2-sqlite3 php8.2-curl \
  php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip php8.2-bcmath \
  certbot python3-certbot-nginx
```

---

## Step 4: Clone Codebase & Configure Permissions

1. Create application directory in `/var/www/`:
```bash
sudo mkdir -p /var/www/gocotechnology.com
sudo chown -R $USER:www-data /var/www/gocotechnology.com
```

2. Clone your repository into `/var/www/gocotechnology.com`:
```bash
git clone YOUR_GIT_REPOSITORY_URL /var/www/gocotechnology.com
cd /var/www/gocotechnology.com
```

3. Install Composer dependencies for production:
```bash
composer install --no-dev --optimize-autoloader
```

4. Set up `.env` file:
```bash
cp .env.example .env
nano .env
```
Ensure the following variables are set:
```ini
APP_NAME="GOCO Technology"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://www.gocotechnology.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=goco_production
DB_USERNAME=goco_user
DB_PASSWORD=YOUR_STRONG_DATABASE_PASSWORD
```

5. Generate Application Key:
```bash
php artisan key:generate
```

6. Configure Directory Permissions:
```bash
sudo chown -R www-data:www-data /var/www/gocotechnology.com/storage /var/www/gocotechnology.com/bootstrap/cache
sudo chmod -R 775 /var/www/gocotechnology.com/storage /var/www/gocotechnology.com/bootstrap/cache
```

---

## Step 5: Configure MySQL Database

1. Log into MySQL console:
```bash
sudo mysql
```

2. Create Database and User:
```sql
CREATE DATABASE goco_production CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'goco_user'@'localhost' IDENTIFIED BY 'YOUR_STRONG_DATABASE_PASSWORD';
GRANT ALL PRIVILEGES ON goco_production.* TO 'goco_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
```

3. Run Database Migrations:
```bash
php artisan migrate --force
```

---

## Step 6: Configure Nginx & SSL Certificate

1. Copy the Nginx configuration:
```bash
sudo cp deployment/gocotechnology.com.conf /etc/nginx/sites-available/gocotechnology.com.conf
sudo ln -s /etc/nginx/sites-available/gocotechnology.com.conf /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
```

2. Test Nginx syntax:
```bash
sudo nginx -t
```

3. Issue SSL Certificate via Let's Encrypt / Certbot:
```bash
sudo certbot --nginx -d gocotechnology.com -d www.gocotechnology.com
```
*Certbot will automatically issue free SSL certificates and update `/etc/nginx/sites-available/gocotechnology.com.conf` with HTTPS redirection.*

4. Restart Nginx:
```bash
sudo systemctl restart nginx
```

---

## Step 7: Enable Automated Deployments

Whenever you push updates to GitHub/Gitea, you can log into your server and run:
```bash
./deploy.sh
```

Or configure GitHub Actions / Webhooks to trigger `./deploy.sh` automatically upon pushing to the `main` branch.

---

## Summary Checklist

- [x] Droplet created on Ubuntu 22.04 LTS
- [x] DNS A records pointing `@` and `www` to Droplet IP
- [x] LEMP (Nginx, PHP 8.2, MySQL) installed & tuned
- [x] Codebase cloned to `/var/www/gocotechnology.com`
- [x] Database created & `php artisan migrate --force` executed
- [x] SSL certificate issued for `https://www.gocotechnology.com`
- [x] Permissions set to `www-data:www-data` on `storage/` and `bootstrap/cache/`
