# Domain Setup Quick Reference Card

**For:** taskcodigital.com Multi-Tenant Setup

---

## 🚀 Quick Setup (5 Steps)

### 1️⃣ DNS Records (At Domain Registrar)

```
Type: A,  Name: @,  Value: YOUR_SERVER_IP
Type: A,  Name: *,  Value: YOUR_SERVER_IP
```

### 2️⃣ Nginx Config

```bash
sudo nano /etc/nginx/sites-available/taskcodigital

# Add:
server {
    listen 80;
    server_name taskcodigital.com *.taskcodigital.com;
    root /var/www/sajjad.site/erp-starterkit/public;
    index index.php;
    
    location / { try_files $uri $uri/ /index.php?$query_string; }
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

# Enable & restart
sudo ln -s /etc/nginx/sites-available/taskcodigital /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl restart nginx
```

### 3️⃣ SSL Certificate

```bash
sudo certbot --nginx -d taskcodigital.com -d *.taskcodigital.com --preferred-challenges dns
```

### 4️⃣ Laravel Config

```bash
# .env
APP_URL=https://taskcodigital.com
SESSION_DOMAIN=.taskcodigital.com

# config/tenancy.php
'central_domains' => ['taskcodigital.com'],

# Cache
php artisan config:cache
```

### 5️⃣ Create Tenant

```bash
curl -X POST https://taskcodigital.com/create-tenant \
  -H "Content-Type: application/json" \
  -d '{"tenant_id": "demo", "company_name": "Demo Co"}'
```

---

## 📋 Common Commands

### Check DNS
```bash
nslookup taskcodigital.com
dig acme.taskcodigital.com
```

### SSL Management
```bash
sudo certbot renew                    # Renew certificates
sudo certbot certificates             # List certificates
sudo certbot renew --dry-run         # Test renewal
```

### Laravel
```bash
php artisan optimize:clear           # Clear all caches
php artisan optimize                 # Cache for production
php artisan tenants:list            # List tenants
```

### Web Server
```bash
sudo systemctl restart nginx         # Restart Nginx
sudo nginx -t                        # Test config
sudo tail -f /var/log/nginx/error.log  # Check logs
```

---

## 🔧 Troubleshooting

| Issue | Solution |
|-------|----------|
| Domain not resolving | Wait 30 min, check DNS with `nslookup` |
| SSL error | Run `sudo certbot renew` |
| 403 Forbidden | `sudo chown -R www-data:www-data /var/www/sajjad.site/erp-starterkit` |
| 500 Error | Check `storage/logs/laravel.log` |
| Tenant not found | Verify domain in DB: `\App\Models\Domain::all()` |

---

## 📱 Test URLs

```
https://taskcodigital.com              → Central app
https://demo.taskcodigital.com         → Demo tenant
https://acme.taskcodigital.com         → ACME tenant
```

---

## ✅ Production Checklist

```bash
- [ ] DNS propagated (nslookup taskcodigital.com)
- [ ] SSL installed (https://taskcodigital.com)
- [ ] APP_DEBUG=false in .env
- [ ] Config cached (php artisan config:cache)
- [ ] Permissions set (chown www-data:www-data)
- [ ] Firewall configured (ufw allow 80,443)
- [ ] Backups scheduled
```

---

**Need detailed help?** See `Custom Domain Setup Guide.md`
