# Sirus CRM - Quick Deployment Checklist

## ⏱️ Pre-Deployment (Do This FIRST)

### Environment Verification
- [ ] Hosting has PHP 7.4+ installed (`php -v` in terminal)
- [ ] MySQL 5.7+ available (check cPanel)
- [ ] SSH access available or FTP working
- [ ] Domain DNS pointing to hosting

### Local Backup
- [ ] All project files backed up locally
- [ ] Database schema backed up locally
- [ ] Configuration template ready

---

## 📦 Step 1: Prepare Configuration (5 minutes)

```bash
# Copy example config to real config
cp public_html/config.example.php public_html/config.php
```

Edit `public_html/config.php`:
- [ ] Database host/name/user/password filled
- [ ] Application URL set to https://yourdomain.com/crm
- [ ] Email sender address configured
- [ ] Brevo API key added (or email service choice)

---

## 🚀 Step 2: Deploy Files (10 minutes)

### Option A: Via cPanel File Manager
1. Log in to cPanel
2. Open File Manager
3. Navigate to public_html
4. Upload all files from `Sirus CRM/public_html/`
5. Set permissions: 755 for folders, 644 for files
6. [ ] Upload complete

### Option B: Via SFTP
```bash
sftp username@yourhost.com
cd public_html
put -r Sirus\ CRM/public_html/*
quit
```
- [ ] Upload complete

### Option C: Via SSH + Git
```bash
ssh username@yourhost.com
cd public_html
git clone https://github.com/yourusername/sirus-crm.git .
```
- [ ] Clone complete

---

## 🗄️ Step 3: Database Setup (5 minutes)

### Via phpMyAdmin (cPanel Dashboard)
1. Open cPanel → phpMyAdmin
2. Click "New" database
3. Name it: `sirus_crm_db`
4. Create user: `sirus_user`
5. Set password (strong!)
6. Grant all privileges
7. Go to Import tab
8. Upload `public_html/api/schema.sql`
9. Click Import
- [ ] Database created and schema imported

### Via SSH
```bash
mysql -u root -p
CREATE DATABASE sirus_crm_db;
CREATE USER 'sirus_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON sirus_crm_db.* TO 'sirus_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

mysql -u sirus_user -p sirus_crm_db < public_html/api/schema.sql
```
- [ ] Database created and schema imported

---

## ✅ Step 4: Verification (5 minutes)

### Test Database Connection
1. Upload this test file temporarily:

```php
<?php
require 'config.php';
require 'api/db.php';
try {
    echo "✅ Success! Database connected.";
} catch (Exception $e) {
    echo "❌ Error: " . $e->getMessage();
}
?>
```

2. Visit: `https://yourdomain.com/crm/test.php`
3. Delete the test file after verification
- [ ] Database connection verified

### Test Web Access
1. Visit `https://yourdomain.com/crm/login.php`
2. Visit `https://yourdomain.com/crm/client-login.php`
- [ ] Pages load without errors

---

## 🔐 Step 5: Security (5 minutes)

```bash
# Via SSH
ssh username@yourhost.com
cd public_html/crm

# Set strict permissions on config
chmod 400 config.php

# Ensure uploads folder is writable
chmod 775 uploads/
chmod 775 api/
```

- [ ] Config permissions set to 400
- [ ] Upload directories writable (775)
- [ ] HTTPS enabled (AutoSSL in cPanel)

---

## 👤 Step 6: Create First Admin (2 minutes)

### Option A: Via phpMyAdmin
1. Open phpMyAdmin
2. Go to `users` table
3. Insert new record:
   - name: `Admin`
   - email: `admin@yourdomain.com`
   - password: Use PASSWORD() function in MySQL
   - role: `Admin`

### Option B: Via SQL
```bash
mysql -u sirus_user -p sirus_crm_db -e "
INSERT INTO users (name, email, password, role) VALUES 
('Admin', 'admin@yourdomain.com', PASSWORD('initial_strong_password'), 'Admin');
"
```

- [ ] Admin user created

### Option C: Via Web Interface (If Setup Script Exists)
1. Visit `https://yourdomain.com/crm/setup.php`
2. Fill in admin details
3. Submit
- [ ] Admin user created

---

## 🧪 Step 7: Test Core Functions (10 minutes)

### Admin Login
- [ ] Visit `https://yourdomain.com/crm/login.php`
- [ ] Login with admin credentials
- [ ] See dashboard (should not have errors)

### Admin Features
- [ ] Click "Finance Dashboard" - loads data
- [ ] Click "Financial Statements" - P&L loads
- [ ] Click "Sales Dashboard" - campaigns load
- [ ] Click "Client Requests" - empty list OK

### Client Login
- [ ] Visit `https://yourdomain.com/crm/client-login.php`
- [ ] (Create test client in database first)
- [ ] Login works
- [ ] See client finance page

---

## 📧 Step 8: Email Configuration (5 minutes)

### Brevo Setup (Recommended)
1. Sign up at https://www.brevo.com/
2. Verify sender email in Brevo
3. Get API key from Settings
4. Add to `config.php`
5. Test by submitting finance request from client
- [ ] Email sending verified

### Alternative: SendGrid
1. Sign up at https://sendgrid.com/
2. Create API key
3. Update config and email API calls
- [ ] Email service configured

---

## 🎯 Post-Deployment (Day 1)

- [ ] Check error logs: `tail -f /home/user/logs/php_errors.log`
- [ ] Verify no database errors
- [ ] Test all admin and client functions
- [ ] Verify email delivery (check Brevo/SendGrid)
- [ ] Create real admin user (change password)
- [ ] Invite first test client

---

## 🔍 Weekly Maintenance

```bash
# Check error logs
tail -f ~/logs/php_errors.log

# Monitor database size
du -sh ~/mysql/sirus_crm_db/

# Check disk space
df -h
```

- [ ] No critical errors
- [ ] Database size reasonable
- [ ] Disk space adequate (>5GB free)

---

## 📊 Success Checklist

✅ Your deployment is successful when:

1. [ ] All files uploaded to `public_html/crm/`
2. [ ] `config.php` configured with real credentials
3. [ ] Database created and schema imported
4. [ ] Admin user created and can login
5. [ ] Dashboard loads without errors
6. [ ] Finance data displays
7. [ ] Clients can login (create test client)
8. [ ] Email service configured and tested
9. [ ] HTTPS/SSL working
10. [ ] No errors in log files

---

## ⚠️ If Something Goes Wrong

**Database Error?**
```bash
# Verify connection
mysql -u sirus_user -p sirus_crm_db -e "SELECT 1;"
```

**File Permission Error?**
```bash
# Fix permissions
find ~/public_html/crm -type d -exec chmod 755 {} \;
find ~/public_html/crm -type f -exec chmod 644 {} \;
chmod 775 ~/public_html/crm/uploads/
```

**Login Not Working?**
```bash
# Check user exists
mysql -u sirus_user -p sirus_crm_db -e "SELECT email, role FROM users;"
```

**Email Not Sending?**
- Verify API key in config.php
- Check sender email is verified in Brevo
- Review Brevo dashboard for delivery status

---

## 📞 Support Resources

- **Hosting Panel**: cPanel Login at your.hosting.server/cpanel
- **Database Admin**: phpMyAdmin via cPanel
- **Email Service**: Brevo Dashboard at https://app.brevo.com/
- **File Manager**: cPanel File Manager
- **SSH Terminal**: Use PuTTY (Windows) or Terminal (Mac/Linux)

---

**Total Deployment Time: ~45 minutes**

Good luck! 🚀
