# SSH & Deployment Guide for reseller.methexis.eu

## Quick Access Commands

### Windows Batch Files (Double-click to run)
Located in `C:\Users\Vlad\`:

- **`ssh-reseller.bat`** - Connect to server via SSH (goes directly to app folder)
- **`deploy-reseller.bat`** - Pull latest code from GitHub and deploy
- **`restart-reseller.bat`** - Restart the Node.js application

### Direct SSH Commands
```bash
# Quick connect (no password needed!)
ssh methexi1@reseller.methexis.eu

# Using SSH config shortcut
ssh reseller-methexi1

# Deploy latest changes
ssh methexi1@reseller.methexis.eu "cd reseller.methexis.eu && git pull"

# Restart application
ssh methexi1@reseller.methexis.eu "cd reseller.methexis.eu && touch tmp/restart.txt"
```

## Server Access Details

### SSH Access (Passwordless)
- **Host:** reseller.methexis.eu
- **User:** methexi1
- **Method:** SSH key authentication (already configured)
- **Directory:** ~/reseller.methexis.eu

### cPanel Access
- **URL:** https://methexis.eu:2083
- **Username:** methexi1
- **Password:** Sb3.T0P{Q;$3Pier}h
- **Node.js App:** Setup Node.js App → reseller.methexis.eu

### Website Access
- **URL:** https://reseller.methexis.eu
- **Admin Login:** office@methexis.eu
- **Admin Password:** Methexis1234

## SSH Configuration

### SSH Config File
Located at `C:\Users\Vlad\.ssh\config`:

```ssh
Host reseller-methexi1
    HostName reseller.methexis.eu
    User methexi1
    IdentityFile ~/.ssh/id_rsa
    StrictHostKeyChecking no
    ServerAliveInterval 60
    ServerAliveCountMax 3
```

### SSH Key
- **Public Key:** `C:\Users\Vlad\.ssh\id_rsa.pub`
- **Private Key:** `C:\Users\Vlad\.ssh\id_rsa`
- **Status:** Installed and working for methexi1 user

## Deployment Process

### 1. Local Development
```bash
# Make changes locally
cd "C:\Web Projects\chocolate-ordering-system"

# Test locally
npm start

# Commit and push to GitHub
git add .
git commit -m "Your commit message"
git push
```

### 2. Deploy to Production
```bash
# Option 1: Use batch file (easiest)
# Double-click C:\Users\Vlad\deploy-reseller.bat

# Option 2: Manual deployment via SSH
ssh methexi1@reseller.methexis.eu "cd reseller.methexis.eu && git pull"

# Option 3: Deploy via cPanel
# Go to cPanel → Git Version Control → Pull or Deploy
```

### 3. Restart Application (if needed)
```bash
# Option 1: Use batch file
# Double-click C:\Users\Vlad\restart-reseller.bat

# Option 2: Via SSH
ssh methexi1@reseller.methexis.eu "cd reseller.methexis.eu && touch tmp/restart.txt"

# Option 3: Via cPanel
# Setup Node.js App → Stop App → Start App
```

## Database Management

### Database Location
- **Local:** `C:\Web Projects\chocolate-ordering-system\database.db`
- **Server:** `~/reseller.methexis.eu/database.db`
- **Type:** SQLite3
- **Tracked in Git:** Yes (automatically deployed with code)

### Database Updates
```bash
# Database changes are automatically deployed with git pull
# To manually backup database on server:
ssh methexi1@reseller.methexis.eu "cd reseller.methexis.eu && cp database.db database_backup_$(date +%Y%m%d).db"
```

## Server Configuration

### Node.js Application Settings
- **Node Version:** 22
- **Entry Point:** server.js
- **Port:** Managed by Phusion Passenger
- **Environment:** Production

### Critical Files on Server
- `.htaccess` - Passenger configuration (DO NOT modify proxy rules!)
- `server.js` - Main application entry point
- `database.db` - SQLite database
- `tmp/restart.txt` - Touch this file to trigger restart

## Troubleshooting

### SSH Connection Issues

#### IP Blocked
- **Symptom:** Connection timeout or too many authentication failures
- **Solution:**
  1. Wait 15-30 minutes (auto-unblocks)
  2. Or contact hosting support to whitelist IP
  3. Or use mobile hotspot/different network

#### SSH Key Not Working
```bash
# Reinstall SSH key
ssh-copy-id methexi1@reseller.methexis.eu
# Password: Sb3.T0P{Q;$3Pier}h
```

### Application Issues

#### Site Shows 503 Error
```bash
# Check .htaccess doesn't have proxy rules
# Should only have Passenger configuration:
ssh methexi1@reseller.methexis.eu "cat reseller.methexis.eu/.htaccess"

# Restart application
ssh methexi1@reseller.methexis.eu "cd reseller.methexis.eu && touch tmp/restart.txt"
```

#### CSS/JS Not Loading
- **Cause:** Usually .htaccess misconfiguration
- **Solution:** Ensure .htaccess only contains Passenger config, no proxy rules

#### Database Not Updating
```bash
# Pull latest from GitHub
ssh methexi1@reseller.methexis.eu "cd reseller.methexis.eu && git pull"

# Verify database file
ssh methexi1@reseller.methexis.eu "ls -la reseller.methexis.eu/database.db"
```

## Git Workflow

### Standard Development Cycle
1. **Develop locally:** Make changes in `C:\Web Projects\chocolate-ordering-system`
2. **Test locally:** Run `npm start` and test at http://localhost:3001
3. **Commit changes:**
   ```bash
   git add .
   git commit -m "Description of changes"
   git push
   ```
4. **Deploy to production:** Double-click `deploy-reseller.bat`
5. **Verify deployment:** Visit https://reseller.methexis.eu

### Handling Database Changes
- Database is tracked in Git (database.db)
- Changes to database structure happen via database.js initialization
- Product/order data changes are included in git commits
- Always backup before major database changes

## Security Notes

### Credentials Storage
- SSH keys stored in `~/.ssh/` (secure)
- cPanel password in this doc (for reference only)
- Admin password hashed in database
- Never commit sensitive API keys or secrets

### Access Control
- SSH limited to methexi1 user
- IP safelisting enabled on server
- Admin panel requires authentication
- Customer access requires login

## Quick Reference Card

```bash
# Connect to server
ssh methexi1@reseller.methexis.eu

# Navigate to app
cd reseller.methexis.eu

# Check app status
ls -la
git status

# View logs
tail -f /home/methexi1/reseller.methexis.eu/error_log

# Quick deploy
git pull && touch tmp/restart.txt

# Backup database
cp database.db "backup_$(date +%Y%m%d_%H%M%S).db"
```

## Contact & Support

- **Hosting Provider:** Methexis hosting on shared CloudLinux/cPanel
- **GitHub Repository:** https://github.com/kevlad/site-comenzi-importuri-distributie
- **Production URL:** https://reseller.methexis.eu
- **Development:** Local at http://localhost:3001

---

*Last Updated: October 27, 2025*
*Created during initial deployment and SSH configuration*