> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/pocketbase/pocketbase/llms.txt
> Use this file to discover all available pages before exploring further.

# Deployment overview

> Learn how to deploy PocketBase to production and understand deployment considerations

PocketBase is a single executable file that you can deploy anywhere. This flexibility makes it suitable for various hosting environments, from traditional VPS servers to modern cloud platforms.

## Deployment options

You can deploy PocketBase using several approaches:

* **Standalone binary**: Download and run the PocketBase executable directly on your server
* **Docker container**: Use containerization for consistent deployment across environments
* **Platform-as-a-Service**: Deploy to platforms like Fly.io, Railway, or DigitalOcean App Platform
* **Traditional VPS**: Run on virtual private servers from providers like AWS, Google Cloud, or DigitalOcean

## System requirements

PocketBase has minimal system requirements:

* **Operating system**: Linux, macOS, or Windows (restore functionality requires Unix-based systems)
* **Memory**: As little as 256MB RAM for small applications
* **Storage**: Depends on your data volume and backup strategy
* **Architecture**: Supports amd64, arm64, and armv7

<Note>
  For production deployments, you should have at least 2x the size of your `pb_data` directory available as free disk space to safely perform backups.
</Note>

## Data directory structure

PocketBase stores all data in the `pb_data` directory:

```
pb_data/
├── data.db              # Main SQLite database
├── data.db-shm          # Shared memory file (temporary)
├── data.db-wal          # Write-ahead log (temporary)
├── backups/             # Local backup files
├── storage/             # Uploaded files
└── logs.db              # Application logs
```

<Warning>
  Always back up the entire `pb_data` directory, not just the database files. The directory contains uploaded files and other critical data.
</Warning>

## Running PocketBase

Start PocketBase with the serve command:

```bash theme={null}
./pocketbase serve
```

Common flags:

* `--http`: Change the HTTP server address (default: `127.0.0.1:8090`)
* `--dir`: Specify a custom data directory (default: `./pb_data`)
* `--publicDir`: Set a custom public directory path
* `--hooksDir`: Set a custom hooks directory path
* `--migrationsDir`: Set a custom migrations directory path

Example with custom configuration:

```bash theme={null}
./pocketbase serve --http="0.0.0.0:80" --dir="/var/lib/pocketbase/data"
```

<Info>
  Binding to `0.0.0.0` makes PocketBase accessible from external networks. Use `127.0.0.1` for local-only access.
</Info>

## Environment variables

PocketBase supports configuration through environment variables:

* **Encryption**: Set the encryption key for sensitive settings
  ```bash theme={null}
  export PB_ENCRYPTION_KEY="your-32-char-encryption-key"
  ```

* **Data directory**: Override the default data directory
  ```bash theme={null}
  export PB_DATA_DIR="/custom/path/to/data"
  ```

## Process management

For production deployments, use a process manager to ensure PocketBase runs continuously:

### systemd (Linux)

Create a systemd service file at `/etc/systemd/system/pocketbase.service`:

```ini theme={null}
[Unit]
Description=PocketBase
After=network.target

[Service]
Type=simple
User=pocketbase
Group=pocketbase
WorkingDirectory=/opt/pocketbase
ExecStart=/opt/pocketbase/pocketbase serve --http="0.0.0.0:8090"
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
```

Enable and start the service:

```bash theme={null}
sudo systemctl enable pocketbase
sudo systemctl start pocketbase
```

### Docker

Create a `Dockerfile`:

```dockerfile theme={null}
FROM alpine:latest

RUN apk add --no-cache ca-certificates

COPY pocketbase /usr/local/bin/pocketbase

EXPOSE 8090

CMD ["/usr/local/bin/pocketbase", "serve", "--http=0.0.0.0:8090"]
```

Run with Docker:

```bash theme={null}
docker run -d \
  -p 8090:8090 \
  -v /path/to/pb_data:/pb_data \
  pocketbase:latest
```

## Reverse proxy

In production, you should run PocketBase behind a reverse proxy like nginx or Caddy for:

* SSL/TLS termination
* Load balancing
* Rate limiting
* Static file serving

### nginx example

```nginx theme={null}
server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:8090;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
```

### Caddy example

```caddy theme={null}
example.com {
    reverse_proxy localhost:8090
}
```

## Next steps

<CardGroup cols={2}>
  <Card title="Going to production" icon="rocket" href="/deployment/going-to-production">
    Learn about production-specific configurations and best practices
  </Card>

  <Card title="Backups" icon="database" href="/deployment/backups">
    Set up automated backups to protect your data
  </Card>

  <Card title="Migrations" icon="code" href="/deployment/migrations">
    Manage database schema changes with migrations
  </Card>
</CardGroup>
