## Production install (Ubuntu VPS, no Docker)

The install script uses **PM2** to run the Medusa backend and Next.js storefront, **Apache** as the reverse proxy, and **Certbot** for SSL. PostgreSQL and Redis run as system services.

### Prerequisites
- **A server**: Ubuntu 22.04/24.04 recommended.
- **DNS**: `DOMAIN` (and `www.DOMAIN`) A record(s) → your server IP.  
  Storefront at `/`, Medusa backend (admin + API) at **`/app`** (default Medusa URL path).
- **Ports open**: 80 + 443 inbound.

### 1) Upload code to the server
Copy the whole project folder to the server (for example `/opt/biomket`).  
If you have an existing database dump, place **`biomket-backend.sql`** in the project root (same folder as `backend/`, `clients/`, `deploy/`). The install script will import it after PostgreSQL is set up.

```bash
cd /opt/biomket
```

### 2) Create production env file

```bash
cp deploy/production.env.example deploy/production.env
nano deploy/production.env
```

Fill in at minimum:
- `DOMAIN`, `CERTBOT_EMAIL`
- `POSTGRES_USER`, `POSTGRES_DB`, `POSTGRES_PASSWORD`
- `JWT_SECRET`, `COOKIE_SECRET`

Optional: `MEDUSA_BACKEND_PATH` (default `/app`), `BACKEND_PORT` (9000), `FRONTEND_PORT` (3000).

### 3) Run install

```bash
sudo bash deploy/install.sh
```

The script will:
- Install Node.js 20, PostgreSQL, Redis, Apache, Certbot, PM2
- Create the PostgreSQL user and database, and import `biomket-backend.sql` if present
- Generate `backend/.env` and `clients/.env` from `deploy/production.env`
- Build backend and frontend, then start them with PM2
- Configure Apache (`/` → storefront, `/app` → backend) and request SSL

### Common commands

```bash
# PM2
pm2 list
pm2 logs biomket-backend
pm2 logs biomket-storefront
pm2 restart biomket-backend
pm2 restart biomket-storefront
pm2 save

# Apache
sudo systemctl status apache2
sudo systemctl reload apache2

# PostgreSQL
sudo -u postgres psql -d biomket -c "\\dt"

# Redis
redis-cli ping
```
