# DEPLOYMENT GUIDE - NEUROBRO V6.0 Dashboard
## cPanel Shared Hosting Deployment

### 📋 DEPLOYMENT CHECKLIST

- [ ] File structure preparation
- [ ] Python environment setup in cPanel
- [ ] Passenger configuration
- [ ] Upload files to server
- [ ] Install Python dependencies
- [ ] Set file permissions
- [ ] Test deployment

---

## 📁 STEP 1: Prepare File Structure

### Upload these files to cPanel `public_html` folder:

```
public_html/
├── dashboard/
│   ├── __init__.py
│   ├── app.py              (Flask application)
│   ├── templates/
│   │   └── dashboard.html
│   └── static/
│       ├── css/
│       │   └── terminal.css
│       └── js/
│           └── app.js
├── neurobroV6.py           (Main screening engine)
├── tickers_idx.txt         (Stock tickers list)
├── free_float_idx.csv      (Free float data)
├── passenger_wsgi.py       (Passenger WSGI entry point)
├── requirements.txt        (Python dependencies)
├── .htaccess             (Apache configuration)
└── config.json            (Persistent config - will be created automatically)
```

---

## 🐍 STEP 2: Setup Python in cPanel

1. **Login to cPanel** → "Setup Python App"
2. **Create Python Application:**
   - Python Version: 3.11 or higher
   - Application Root: `public_html`
   - Application URL: Your domain/subdomain
   - Application Startup File: `passenger_wsgi.py`
   - Application Entry Point: `application`

3. **Go to Application → "Edit"** → "Install Python Packages"
   - Upload `requirements.txt` or install manually:
   ```
   flask==3.0.0
   yfinance==0.2.44
   pandas==2.2.1
   numpy==1.26.3
   ```

---

## ⚙️ STEP 3: Configure Application

### Update `.htaccess`:
Replace `USERNAME` with your actual cPanel username:
```apache
PassengerAppRoot /home/YOUR_USERNAME/public_html
```

### Test Python Path:
In cPanel terminal, check your Python path:
```bash
which python3
# Usually: /usr/bin/python3 or /usr/local/bin/python3
```

Update `.htaccess` if needed:
```apache
PassengerPython /usr/bin/python3
```

---

## 📤 STEP 4: Upload Files

### Option A: cPanel File Manager
1. Go to "File Manager" → `public_html`
2. Upload all files
3. Extract any zip archives if needed

### Option B: FTP/SFTP
```bash
# Example with SFTP
sftp username@yourdomain.com
cd public_html
put -r dashboard/
put *.py
put *.txt
put *.csv
put .htaccess
```

### Option C: Git (if available)
```bash
git clone <your-repo-url> .
```

---

## 🔐 STEP 5: Set File Permissions

### Critical Files (600/644):
```bash
chmod 644 dashboard/app.py
chmod 644 neurobroV6.py
chmod 644 passenger_wsgi.py
chmod 644 .htaccess
```

### Data Files (666):
```bash
chmod 666 tickers_idx.txt
chmod 666 free_float_idx.csv
chmod 666 config.json
```

### Directories (755):
```bash
chmod 755 dashboard/
chmod 755 dashboard/templates/
chmod 755 dashboard/static/
```

---

## 🧪 STEP 6: Test Deployment

### 1. Check Passenger Status:
In cPanel → "Setup Python App" → Check app status

### 2. Check Error Logs:
```
cPanel → "Errors" page
OR
/home/USERNAME/logs/error_log
```

### 3. Test Application:
Visit your domain and check:
- [ ] Homepage loads correctly
- [ ] Static files (CSS/JS) load
- [ ] API endpoints respond
- [ ] No 500/403 errors

---

## 🔧 TROUBLESHOOTING

### Common Issues & Solutions:

**1. 500 Internal Server Error**
- Check file permissions (644 for Python files)
- Verify passenger_wsgi.py path
- Check error logs for specific issues

**2. 403 Forbidden**
- File permissions too restrictive (should be 644/755)
- .htaccess configuration issue

**3. Static files not loading**
- Check dashboard/static/ directory permissions (755)
- Verify .htaccess allows static file access

**4. Module not found**
- Reinstall dependencies in cPanel Python
- Check Python version compatibility
- Verify requirements.txt uploaded correctly

**5. Application crashes**
- Memory issues: reduce batch size in app.py
- Timeout: increase passenger timeout in cPanel
- Check if all dependencies are installed

---

## 🚀 PRODUCTION OPTIMIZATIONS

### 1. Memory Optimization:
Update `dashboard/app.py` batch size:
```python
batch_size = 25  # Reduce from 50 if needed
```

### 2. Timeout Settings:
In cPanel → "Setup Python App" → "Edit":
- Increase timeout to 180 seconds

### 3. Error Handling:
Ensure production-ready configuration:
```python
app.run(debug=False, host='0.0.0.0', port=5001)
```

---

## 📊 MONITORING

### Check Logs:
```bash
# Application logs
tail -f /home/USERNAME/logs/passenger.log

# Error logs
tail -f /home/USERNAME/logs/error_log
```

### Monitor Performance:
- cPanel "Resource Usage"
- Application response time
- Memory usage during screening

---

## 🔄 UPDATES

### To Update Application:
1. Upload new files via FTP/cPanel
2. Restart Python app in cPanel
3. Clear browser cache

### Database Updates:
- Upload new tickers_idx.txt
- Upload new free_float_idx.csv
- No database restart needed

---

## 📞 SUPPORT

If deployment fails:
1. Check cPanel error logs first
2. Verify Python dependencies installed
3. Test with simple Flask app first
4. Contact hosting support for Python/Passenger issues

---

## ✅ FINAL CHECKLIST

Before going live:
- [ ] All files uploaded correctly
- [ ] File permissions set properly
- [ ] Python dependencies installed
- [ ] Passenger app running
- [ ] Homepage loads without errors
- [ ] API endpoints functional
- [ ] Screening works (test with small dataset)
- [ ] Error logging works

---

**Deployment URL**: `https://yourdomain.com`
**Admin Panel**: cPanel → Setup Python App

**Last Updated**: July 2026
**Version**: NEUROBRO V6.0