# Apache DocumentRoot Configuration

## Problem

Your Apache DocumentRoot is currently set to the `public/` folder, which means:
- `http://localhost/` maps to `public/`
- `http://localhost/api/` looks for `public/api/` (which doesn't exist)
- The actual API is at `api/` (one level up from public)

## Solution: Change DocumentRoot

### For XAMPP (Windows):

1. **Open Apache config file**:
   - File location: `C:\xampp\apache\conf\httpd.conf`
   - Open with Notepad or any text editor (as Administrator)

2. **Find DocumentRoot** (around line 220-240):
   ```apache
   DocumentRoot "C:/xampp/htdocs"
   <Directory "C:/xampp/htdocs">
   ```

3. **Change to your project folder**:
   ```apache
   DocumentRoot "C:/Development/Fellowship Housing/web-poc"
   <Directory "C:/Development/Fellowship Housing/web-poc">
   ```

4. **Find AllowOverride** (around line 250):
   ```apache
   <Directory "C:/xampp/htdocs">
       AllowOverride None
   ```

5. **Change to**:
   ```apache
   <Directory "C:/Development/Fellowship Housing/web-poc">
       AllowOverride All
   ```

6. **Important: Enable mod_rewrite** (if not already enabled)

   Find this line (around line 150):
   ```apache
   #LoadModule rewrite_module modules/mod_rewrite.so
   ```

   Remove the `#` to uncomment it:
   ```apache
   LoadModule rewrite_module modules/mod_rewrite.so
   ```

7. **Save the file and restart Apache**:
   - Open XAMPP Control Panel
   - Click "Stop" next to Apache
   - Wait 2 seconds
   - Click "Start"

### After Restart:

Test these URLs:
- `http://localhost/` → Should show the login screen (from public/index.html)
- `http://localhost/api/v1/test.php` → Should show JSON: `{"success": true, ...}`
- `http://localhost/public/index.html` → Should show login screen

If all three work, the configuration is correct!

## Alternative Solution (If You Can't Change DocumentRoot)

If you cannot or don't want to change the DocumentRoot, you can use a virtual host instead:

### Create a Virtual Host:

1. **Open**: `C:\xampp\apache\conf\extra\httpd-vhosts.conf`

2. **Add at the end**:
   ```apache
   <VirtualHost *:80>
       ServerName fellowship.local
       DocumentRoot "C:/Development/Fellowship Housing/web-poc"

       <Directory "C:/Development/Fellowship Housing/web-poc">
           Options Indexes FollowSymLinks
           AllowOverride All
           Require all granted
       </Directory>
   </VirtualHost>
   ```

3. **Edit Windows hosts file**:
   - File: `C:\Windows\System32\drivers\etc\hosts` (open as Administrator)
   - Add this line:
     ```
     127.0.0.1 fellowship.local
     ```

4. **Restart Apache**

5. **Access the app**:
   - Use: `http://fellowship.local/` instead of `http://localhost/`
   - API will work at: `http://fellowship.local/api/v1/test.php`

## Verification Steps

After making changes, test in this order:

### 1. Test API Directly
Visit: `http://localhost/api/v1/test.php`

**Expected response** (JSON):
```json
{
  "success": true,
  "message": "API is working!",
  "php_version": "8.x.x",
  "time": "2026-01-22 ..."
}
```

**If you see HTML** (the index.html page):
- DocumentRoot is still pointing to `public/`
- Go back and check your httpd.conf changes
- Make sure you restarted Apache

### 2. Test Login Screen
Visit: `http://localhost/`

**Expected**: Login screen with purple background and logo

**If you get a folder listing**:
- The .htaccess isn't being read
- Check that `AllowOverride All` is set
- Check that mod_rewrite is enabled

### 3. Test Authentication
1. Enter a phone number
2. Click "Send Code"
3. Check browser console (F12)

**Expected**:
- Network tab shows: `POST /api/v1/auth/request-code.php` with status 200
- Response should be JSON with success message
- No "Unexpected token" errors

## Troubleshooting

### "403 Forbidden" Error
This means Apache can't access the directory.

**Fix**: Add this to your Directory block in httpd.conf:
```apache
<Directory "C:/Development/Fellowship Housing/web-poc">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
```

### Still Getting index.html for API Calls
1. Check DocumentRoot is set correctly
2. Restart Apache (stop and start, don't just restart)
3. Clear browser cache (Ctrl+Shift+R)
4. Check .htaccess in root has the API passthrough rule:
   ```apache
   RewriteCond %{REQUEST_URI} ^/api/
   RewriteRule ^ - [L]
   ```

### mod_rewrite Not Working
1. Open httpd.conf
2. Find: `#LoadModule rewrite_module modules/mod_rewrite.so`
3. Remove the `#`
4. Restart Apache

## Current File Structure

After DocumentRoot change, URLs map like this:

```
http://localhost/              → public/index.html (via .htaccess)
http://localhost/css/          → public/css/
http://localhost/js/           → public/js/
http://localhost/api/v1/       → api/v1/ (direct access)
http://localhost/includes/     → BLOCKED (by .htaccess)
http://localhost/.htaccess     → BLOCKED (by .htaccess)
```

This is the correct and secure setup!

## Summary

**Current Problem**: DocumentRoot = `public/` folder
**Solution**: Change DocumentRoot = project root folder
**Why**: API files are in `/api/`, not `/public/api/`

Once you make this change, everything will work correctly!
