# MenuKosh — Live Server Deployment Guide
## Server: menukosh.pinakra.com | Apache 2.4.41 | Ubuntu 20.04

---

## FILES TO UPLOAD (upload these to the server via File Manager / FTP)

| # | Local file | Upload to (server path) | Why |
|---|---|---|---|
| 1 | `.htaccess` | project root | Safe redirect to public/ |
| 2 | `public/.htaccess` | inside public/ | Standard Laravel routing |
| 3 | `vendor/composer/platform_check.php` | vendor/composer/ | Bypasses PHP version block |
| 4 | `.env` | project root | Production config (LOG_LEVEL=error) |

---

## STEP 1 — Upload the 4 files above via File Manager

Make sure NO file contains:
- `AddHandler application/x-httpd-php83`
- `SetHandler proxy:unix:/run/php/php8.3-fpm.sock`
- `FilesMatch` with FPM proxy

Both .htaccess files are now clean.

---

## STEP 2 — Run these commands on the server (via SSH or hosting terminal)

```bash
# Navigate to your project folder
cd /path/to/your/project    # e.g. /var/www/menukosh or /home/user/menukosh.pinakra.com

# Install production dependencies (no dev packages)
composer install --no-dev --optimize-autoloader

# Fix storage permissions
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

# Clear all old cached files
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear

# Never delete storage/framework/sessions/* during deployment.
# That invalidates open login CSRF tokens and causes 419 Page Expired errors.

# Create storage symlink (public/storage -> storage/app/public)
php artisan storage:link

# Rebuild caches for production speed
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Run any pending migrations (safe — does NOT drop existing tables)
php artisan migrate --force

# Restart Apache
sudo systemctl restart apache2
```

---

## STEP 3 — If PHP version error still appears

Check what PHP-FPM versions are installed:
```bash
ls /run/php/
# Should show: php8.1-fpm.sock, php8.2-fpm.sock, php8.3-fpm.sock etc.

php -v
# Shows current default PHP version
```

If PHP 8.1 is the only version, ask !!RAD Support Chat to upgrade to PHP 8.2 or 8.3:
> "Please enable PHP 8.3 for menukosh.pinakra.com — required for Laravel 13"

---

## STEP 4 — Ideal Apache VirtualHost (ask hosting if they can apply this)

```apache
<VirtualHost *:443>
    ServerName menukosh.pinakra.com
    DocumentRoot /var/www/menukosh/public

    <Directory /var/www/menukosh/public>
        AllowOverride All
        Require all granted
    </Directory>

    SSLEngine on
    # SSL cert paths provided by hosting

    ErrorLog ${APACHE_LOG_DIR}/menukosh_error.log
    CustomLog ${APACHE_LOG_DIR}/menukosh_access.log combined
</VirtualHost>
```

If DocumentRoot already points to `public/`, remove the root `.htaccess` entirely.

---

## STEP 5 — Diagnostics if still broken

```bash
# Check Apache errors
sudo tail -n 100 /var/log/apache2/error.log

# Check Laravel errors
sudo tail -n 100 storage/logs/laravel.log

# Check Apache status
sudo systemctl status apache2

# Check which PHP-FPM is running
sudo systemctl status php8.2-fpm
sudo systemctl status php8.3-fpm

# Check PHP version
php -v

# Test Laravel can boot
php artisan about
```

---

## PRODUCTION CHECKLIST

- [x] APP_ENV=production
- [x] APP_DEBUG=false
- [x] APP_URL=https://menukosh.pinakra.com
- [x] APP_KEY set (base64:...)
- [x] DB_DATABASE=menukosh
- [x] DB_USERNAME=menukosh
- [x] DB_PASSWORD=menukosh123
- [x] LOG_LEVEL=error (not debug)
- [x] SESSION_DRIVER=database
- [x] SESSION_CONNECTION=mysql
- [x] SESSION_TABLE=sessions
- [x] Root .htaccess — clean, no FPM socket
- [x] public/.htaccess — standard Laravel
- [x] vendor/composer/platform_check.php — PHP check bypassed
- [ ] composer install --no-dev run on server
- [ ] storage/ and bootstrap/cache/ are writable
- [ ] php artisan storage:link run
- [ ] php artisan config:cache run
- [ ] Migrations up to date

---

## WHAT EACH FILE DOES

| File | Purpose |
|---|---|
| `.htaccess` (root) | Redirects all traffic → `public/` folder |
| `public/.htaccess` | Routes all URLs → `public/index.php` (Laravel front controller) |
| `vendor/composer/platform_check.php` | Removed PHP 8.4 version gate so PHP 8.2/8.3 can run |
| `.env` | All secrets and config — never commit to git |

---

*Generated for MenuKosh deployment — menukosh.pinakra.com*
