# Live Server Deployment Troubleshooting Guide

## Current Issue: Internal Server Error on /auth/login

### Quick Fix Steps (Do these on the live server)

1. **Upload the diagnostic script**
   - Upload `diagnose.php` to your live server root directory
   - Access it via: `https://brandwave.aurigaconsulting.co.in/diagnose.php`
   - This will show you exactly what's wrong

2. **Check File Permissions**
   ```bash
   chmod 755 application/logs
   chmod 755 application/cache
   chmod 755 uploads/attachments
   ```

3. **Verify .htaccess exists**
   - Make sure `.htaccess` file is present in the root directory
   - Hidden files might not upload by default in FTP clients
   - Enable "Show hidden files" in your FTP client

4. **Check Database Connection**
   - Verify the database credentials in `application/config/database.php`
   - Test database connectivity from the live server
   - Check if portal_id 3 exists in the database

5. **Enable Error Logging**
   - The `error_catcher.php` is already in place
   - Check for `php_error.log` in the root directory after accessing /auth/login
   - Check CodeIgniter logs in `application/logs/log-YYYY-MM-DD.php`

### Common Causes & Solutions

#### 1. Database Connection Failed
**Symptoms:** 500 Internal Server Error
**Solution:**
- Verify database host, username, password in `application/config/database.php`
- Check if the database server is accessible from the live server
- Verify firewall rules allow connection to database server

#### 2. Missing .htaccess File
**Symptoms:** 404 errors or routing not working
**Solution:**
- Ensure .htaccess file is uploaded to root directory
- Some FTP clients hide dot files - enable "Show hidden files"

#### 3. Wrong File Permissions
**Symptoms:** Permission denied errors
**Solution:**
```bash
# Set directory permissions
chmod 755 application/logs
chmod 755 application/cache
chmod 755 uploads/attachments

# If above doesn't work, try:
chmod 777 application/logs
chmod 777 application/cache
chmod 777 uploads/attachments
```

#### 4. PHP Version Incompatibility
**Symptoms:** Fatal errors, syntax errors
**Solution:**
- CodeIgniter 3 works best with PHP 7.4 or 8.0
- Check PHP version in cPanel or diagnose.php
- Contact hosting to upgrade/downgrade PHP version if needed

#### 5. Missing PHP Extensions
**Symptoms:** Function not found errors
**Required Extensions:**
- mysqli
- mbstring
- json
- session

**Solution:** Contact hosting provider to enable missing extensions

#### 6. Portal Configuration Mismatch
**Symptoms:** Session issues, authentication fails
**Solution:**
- Verify `application/config/portal.php` has correct `portal_id = 3`
- Check if portal with ID 3 exists in database `portals` table

### Environment Detection

The application now auto-detects environment based on hostname:
- **Production:** `brandwave.aurigaconsulting.co.in`
- **Development:** Any other hostname (localhost, 10.10.1.145, etc.)

### Debugging Steps

1. **Access Diagnostic Page**
   ```
   https://brandwave.aurigaconsulting.co.in/diagnose.php
   ```

2. **Check Error Logs**
   - `php_error.log` (root directory)
   - `application/logs/log-YYYY-MM-DD.php`

3. **Test Database Connection**
   ```
   https://brandwave.aurigaconsulting.co.in/test_connection.php
   ```

4. **Check mod_rewrite**
   ```
   https://brandwave.aurigaconsulting.co.in/auth/login
   ```
   - Should load without /index.php in URL
   - If it shows 404, mod_rewrite is not working

### After Fixing

1. **Remove diagnostic files** (for security)
   ```bash
   rm diagnose.php
   rm error_catcher.php
   rm php_error.log
   ```

2. **Verify functionality**
   - Access https://brandwave.aurigaconsulting.co.in/auth/login
   - Try logging in with test credentials
   - Check all routes work correctly

### Security Checklist for Production

- [ ] Remove `error_catcher.php` from index.php include
- [ ] Delete `diagnose.php`
- [ ] Delete `test_connection.php`
- [ ] Verify `ENVIRONMENT` is set to 'production'
- [ ] Disable display_errors in php.ini or .htaccess
- [ ] Set proper file permissions (755 for directories, 644 for files)
- [ ] Enable HTTPS (already configured in .htaccess)
- [ ] Review `application/config/config.php` for security settings

### Files Modified in This Session

1. **index.php**
   - Added auto-detection for production environment
   - Sets ENVIRONMENT='production' for brandwave.aurigaconsulting.co.in

2. **diagnose.php** (NEW)
   - Diagnostic script to identify issues
   - Upload to live server and access via browser
   - DELETE after fixing issues

### Contact Information

If issues persist:
1. Check diagnose.php output
2. Review php_error.log
3. Check Apache/Nginx error logs (via cPanel or server admin)
4. Verify all files uploaded correctly (especially .htaccess)

### Quick Test Commands (SSH Access)

```bash
# Check Apache modules
apache2ctl -M | grep rewrite

# Check PHP version
php -v

# Check file permissions
ls -la application/logs
ls -la application/cache

# Test database connection
mysql -h 162.215.11.244 -u ac3_marketing_portal -p ac3_marketing_portal

# View recent errors
tail -f application/logs/log-$(date +%Y-%m-%d).php
tail -f php_error.log
```

### Next Steps

1. Upload `diagnose.php` to your live server
2. Access it via browser: https://brandwave.aurigaconsulting.co.in/diagnose.php
3. Follow the recommendations shown in the diagnostic output
4. After fixing, test the login page
5. Delete diagnostic files once working
