# VPS Deployment (test.duiclick.com)

Deploy without cPanel. **Do not share SSH passwords in chat** — use SSH keys.

## One-time VPS setup (15 minutes)

### 1. Point DNS

In your domain DNS, add an **A record**:

| Host | Value |
|------|--------|
| `test` | Your VPS IP address |

### 2. SSH into VPS

```bash
ssh root@YOUR_VPS_IP
```

### 3. Clone and install

```bash
cd /var/www
git clone https://github.com/mhr01828/Laravel-11-Project.git saas-accounting
cd saas-accounting
chmod +x scripts/deploy/*.sh
```

Edit database settings:

```bash
cp .env.example .env
nano .env
```

Set at minimum:

```env
APP_URL=https://test.duiclick.com
APP_ENV=production
APP_DEBUG=false

DB_DATABASE=saas_accounting
DB_USERNAME=saas
DB_PASSWORD=your_strong_password
```

Create MySQL database:

```bash
mysql -e "CREATE DATABASE saas_accounting CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -e "CREATE USER 'saas'@'localhost' IDENTIFIED BY 'your_strong_password';"
mysql -e "GRANT ALL ON saas_accounting.* TO 'saas'@'localhost'; FLUSH PRIVILEGES;"
```

Run install (nginx + PHP + migrate):

```bash
sudo APP_URL=https://test.duiclick.com bash scripts/deploy/vps-install.sh
```

### 4. HTTPS (Let's Encrypt)

```bash
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d test.duiclick.com
```

---

## Every update (after I push to GitHub)

**On the VPS:**

```bash
cd /var/www/saas-accounting
bash scripts/deploy/vps-update.sh
```

**Or from your laptop** (after `ssh-copy-id root@YOUR_VPS_IP`):

```bash
export VPS_HOST=root@YOUR_VPS_IP
bash scripts/deploy/vps-update.sh   # if you cloned repo locally
# OR
bash scripts/deploy/deploy-to-vps.sh
```

---

## Optional: auto-deploy on every GitHub push

On VPS, create a deploy key with read access to the private repo, then:

```bash
crontab -e
```

Add (checks GitHub every 5 minutes — simple approach):

```cron
*/5 * * * * cd /var/www/saas-accounting && git fetch origin main && [ $(git rev-parse HEAD) != $(git rev-parse origin/main) ] && bash scripts/deploy/vps-update.sh >> /var/log/saas-deploy.log 2>&1
```

Better: use GitHub Actions with your VPS SSH key stored as a GitHub Secret (`VPS_HOST`, `VPS_SSH_KEY`).

---

## Default logins (after migrate --seed)

| | |
|--|--|
| Company | `DEMO` / `admin` / `Demo@1234` |
| Super Admin | `https://test.duiclick.com/sadmin` / `admin@saasaccounting.com` / `Admin@1234` |

---

## Troubleshooting

```bash
tail -50 /var/www/saas-accounting/storage/logs/laravel.log
sudo nginx -t
sudo systemctl status php8.3-fpm nginx mysql
```
