# Troubleshooting 500 Internal Server Error

## Step 1: Basic PHP Test
1. Upload the `debug.php` file to your root directory
2. Access it via: `https://simpler.dannel.co.za/debug.php`
3. Check what errors are displayed

## Step 2: Test Simple API
1. Access the test endpoint: `https://simpler.dannel.co.za/api/v1/test.php`
2. This should show you the API status and any errors

## Step 3: Check Server Error Logs
Look for PHP error logs in:
- `/var/log/apache2/error.log`
- `/var/log/nginx/error.log`
- `~/logs/error.log`
- Or check cPanel error logs

## Step 4: Common Issues and Fixes

### Issue 1: Path Problems
The most likely issue is the file paths in the API. I've fixed this by changing:
```php
require_once 'config/config.php';
```
to:
```php
require_once '../../config/config.php';
```

### Issue 2: Database Connection
Check your database credentials in `config/config.php`:
```php
define('DB_HOST', 'localhost');
define('DB_NAME', 'dannelcv_mobile');
define('DB_USER', 'dannelcv_dev');
define('DB_PASS', 'Dannel@2024!');
```

### Issue 3: PHP Extensions
Ensure these extensions are installed:
- mysqli or PDO
- json
- curl

### Issue 4: File Permissions
Set correct permissions:
```bash
chmod 755 api/
chmod 755 api/v1/
chmod 644 api/v1/index.php
chmod 644 config/config.php
chmod 755 classes/
chmod 644 classes/*.php
```

### Issue 5: .htaccess Issues
If the current .htaccess is causing issues, try replacing it with `.htaccess.debug`

## Step 5: Testing Order
1. First, test `debug.php` in root
2. Then test `api/v1/test.php`
3. Finally test the main API endpoints

## Step 6: Manual Testing
Try accessing these URLs directly:
- `https://simpler.dannel.co.za/debug.php`
- `https://simpler.dannel.co.za/api/v1/test.php`
- `https://simpler.dannel.co.za/api/v1/ping` (should fail but show error)

## Common Error Messages and Solutions

### "Class not found"
- Check file paths in require_once statements
- Ensure all class files exist

### "Database connection failed"
- Verify database credentials
- Check if database exists
- Ensure database user has proper permissions

### "Headers already sent"
- Remove any output before header() calls
- Check for BOM in PHP files

### "Parse error"
- Check PHP syntax
- Ensure all files have closing `?>` tags (or remove them)

## Quick Fix Script
Run this PHP script to check everything:

```php
<?php
// Quick diagnostic
echo "=== PHP DIAGNOSTIC ===\n";
echo "PHP Version: " . phpversion() . "\n";
echo "Current Directory: " . getcwd() . "\n";
echo "Script: " . __FILE__ . "\n";
echo "\n=== EXTENSIONS ===\n";
foreach(['mysqli', 'pdo', 'json', 'curl'] as $ext) {
    echo "$ext: " . (extension_loaded($ext) ? "OK" : "MISSING") . "\n";
}
echo "\n=== FILES ===\n";
$files = [
    'config/config.php',
    'classes/Database.php',
    'classes/Auth.php',
    'api/v1/index.php'
];
foreach($files as $file) {
    echo "$file: " . (file_exists($file) ? "EXISTS" : "MISSING") . "\n";
}
?>
```

Save this as `quick-check.php` and run it from your root directory.
