# cPanel Deployment

## Database

1. Open cPanel.
2. Go to **MySQL Databases**.
3. Create a database, for example `cpuser_pantry_hyper`.
4. Create a MySQL user.
5. Assign the user to the database.
6. Grant all required permissions.
7. Add the credentials to `.env`:

```env
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=cpuser_pantry_hyper
DB_USERNAME=cpuser_pantry_user
DB_PASSWORD=secure-password
```

## Application Upload

Upload the project outside `public_html` where possible, for example:

```text
/home/USERNAME/pantry-hyper
```

Install dependencies:

```bash
cd /home/USERNAME/pantry-hyper
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
php artisan migrate --force
php artisan db:seed --force
php artisan pantry:create-admin
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

## Public Directory

Preferred setup: set the cPanel domain or subdomain document root to:

```text
/home/USERNAME/pantry-hyper/public
```

This keeps `.env`, `vendor`, `storage`, application code and configuration out of public web access.

If the host does not allow changing the document root, place only the contents of Laravel's `public` directory in `public_html` and update `public_html/index.php` paths to point to the real application directory. Do not move the whole Laravel application into `public_html`.

## Storage

Run:

```bash
php artisan storage:link
```

If symlinks are blocked, configure cPanel to expose `/storage/app/public` through a protected alias or use a small controlled media-serving route. Do not expose the full `storage` directory.

## Permissions

Ensure these directories are writable by the PHP user:

```text
storage
bootstrap/cache
```

## HTTPS

Enable AutoSSL or install a valid certificate. Set:

```env
APP_URL=https://your-domain.co.za
SESSION_SECURE_COOKIE=true
```

## SMTP

Configure:

```env
MAIL_MAILER=smtp
MAIL_HOST=
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=orders@your-domain.co.za
MAIL_FROM_NAME="Pantry Hyper"
```

## PayFast

Set credentials and callback URLs:

```env
PAYFAST_ENABLED=true
PAYFAST_SANDBOX=false
PAYFAST_MERCHANT_ID=
PAYFAST_MERCHANT_KEY=
PAYFAST_PASSPHRASE=
PAYFAST_RETURN_URL="${APP_URL}/checkout/payment/return"
PAYFAST_CANCEL_URL="${APP_URL}/checkout/payment/cancel"
PAYFAST_NOTIFY_URL="${APP_URL}/payments/payfast/itn"
```

Payment is only marked paid from the server notification route, not from the customer return URL.

## Cron Jobs

Add this cPanel cron job every minute:

```bash
php /home/USERNAME/pantry-hyper/artisan schedule:run
```

The scheduler releases expired stock reservations and can later run stale order cleanup and promotion housekeeping.

## Assets

Compile assets locally or on the server if Node is available:

```bash
npm install
npm run build
```

Production does not require a running Node.js process.
