# AlmaLinux 8 Deployment Guide - Quick Start

## Your Server Info
- **IP**: 173.231.220.198
- **OS**: AlmaLinux 8.10
- **Domain**: annallc.com
- **VPS**: InMotion 12GB NVMe

---

## 🚀 Quick Deployment (Copy & Paste)

### Step 1: Connect to VPS
```bash
ssh root@173.231.220.198
```
*Enter your root password when prompted*

### Step 2: Run Automated Deployment
```bash
curl -o deploy.sh https://raw.githubusercontent.com/nsanthosh718/anna-stockroom-enterprise/main/scripts/deploy-almalinux.sh
chmod +x deploy.sh
./deploy.sh
```

### Step 3: Configure MongoDB
```bash
mongosh
```

In MongoDB shell, copy/paste:
```javascript
use admin
db.createUser({
  user: "annaadmin",
  pwd: "Anna2024!Admin#Secure",
  roles: ["userAdminAnyDatabase", "readWriteAnyDatabase"]
})

use anna_stockroom
db.createUser({
  user: "annaapp",
  pwd: "Anna2024!App#Secure",
  roles: [{role: "readWrite", db: "anna_stockroom"}]
})

exit
```

### Step 4: Enable MongoDB Auth
```bash
nano /etc/mongod.conf
```

Add these lines:
```yaml
security:
  authorization: enabled
```

Save (Ctrl+X, Y, Enter) and restart:
```bash
systemctl restart mongod
```

### Step 5: Generate JWT Secret
```bash
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
```
*Copy the output - you'll need it next*

### Step 6: Configure Environment
```bash
cd /var/www/anna-stockroom
nano .env
```

Update with these values:
```env
NODE_ENV=production
PORT=3001
DOMAIN=annallc.com

JWT_SECRET=PASTE_YOUR_GENERATED_SECRET_HERE
JWT_EXPIRE=7d

MONGODB_URI=mongodb://annaapp:Anna2024!App#Secure@localhost:27017/anna_stockroom?authSource=anna_stockroom

RATE_LIMIT_WINDOW=15
RATE_LIMIT_MAX=100
```

Save (Ctrl+X, Y, Enter)

### Step 7: Start Application
```bash
cd /var/www/anna-stockroom
pm2 start ecosystem.config.js --env production
pm2 save
pm2 startup
```
*Copy and run the command PM2 outputs*

### Step 8: Configure Nginx
```bash
nano /etc/nginx/conf.d/anna-stockroom.conf
```

Paste this configuration:
```nginx
server {
    listen 80;
    server_name annallc.com www.annallc.com;

    access_log /var/log/nginx/anna-stockroom-access.log;
    error_log /var/log/nginx/anna-stockroom-error.log;

    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }

    location /uploads {
        alias /var/www/anna-stockroom/uploads;
        expires 30d;
    }
}
```

Save and test:
```bash
nginx -t
systemctl reload nginx
```

### Step 9: Install SSL Certificate
```bash
certbot --nginx -d annallc.com -d www.annallc.com
```

Follow prompts:
- Enter email
- Agree to terms
- Choose option 2 (redirect to HTTPS)

### Step 10: Verify Deployment
```bash
# Check services
systemctl status mongod nginx
pm2 status

# Test application
curl http://localhost:3001/api/health

# View logs
pm2 logs anna-stockroom --lines 50
```

---

## ✅ Access Your Application

Visit: **https://annallc.com**

**Default Login:**
- Email: `aa1@hotel.com`
- Password: `password123`

**⚠️ CHANGE PASSWORD IMMEDIATELY!**

---

## 🔧 Useful Commands

```bash
# Restart application
pm2 restart anna-stockroom

# View logs
pm2 logs anna-stockroom
tail -f /var/log/nginx/anna-stockroom-error.log

# Check status
pm2 status
systemctl status mongod nginx

# Update application
cd /var/www/anna-stockroom
git pull
npm install --production
pm2 restart anna-stockroom
```

---

## 🆘 Troubleshooting

### Application won't start
```bash
pm2 logs anna-stockroom --lines 100
```

### MongoDB connection error
```bash
systemctl status mongod
mongosh -u annaapp -p --authenticationDatabase anna_stockroom
```

### Nginx error
```bash
nginx -t
tail -f /var/log/nginx/error.log
```

### Port already in use
```bash
lsof -i :3001
kill -9 PID
```

---

## 📝 Passwords to Save

**MongoDB Admin:**
- Username: annaadmin
- Password: Anna2024!Admin#Secure

**MongoDB App:**
- Username: annaapp  
- Password: Anna2024!App#Secure

**JWT Secret:**
- (Generated in Step 5)

**Application Admin:**
- Email: aa1@hotel.com
- Password: password123 (CHANGE THIS!)

---

## ⏱️ Estimated Time: 45 minutes

**Need help?** Contact support@annallc.com
