# Deploying the Laravel API on cPanel / Apache

## Recommended (best)

Point the subdomain or folder **document root** to the `public` directory:

```
/home/.../new.burundilogistics.com/api/public
```

In cPanel: **Domains** → subdomain → **Document Root** → set to `.../api/public`.

Then open: `https://new.burundilogistics.com/api/` (or map the subdomain root directly to `public`).

`.env`:

```
APP_URL=https://new.burundilogistics.com/api
```

---

## Alternative: document root = `api/` (project root)

Upload the whole `api` folder. This repo includes:

- `api/.htaccess` — rewrite to `public/`
- `api/index.php` — fallback if rewrite is disabled

If you still see **“Index of /api”**:

1. Confirm `.htaccess` is uploaded (show hidden files in File Manager).
2. In cPanel → **Apache Configuration** or **MultiPHP**, ensure **AllowOverride** is enabled for this path (often “All” on shared hosting).
3. If the site URL is `https://new.burundilogistics.com/api/`, edit `api/.htaccess` and **uncomment**:
   ```apache
   RewriteBase /api/
   ```
4. Prefer setting **Directory Index** to `index.php` in cPanel for that folder.
5. **Disable directory listing** (Indexes) in cPanel for that path.

---

## After deploy

```bash
cd api
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan storage:link
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

Permissions: `storage/` and `bootstrap/cache/` writable by the web server.

---

## Nginx (not Apache)

Do not use `.htaccess`. Example:

```nginx
root /path/to/api/public;
index index.php;
location / {
    try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    include fastcgi_params;
}
```
