# ![Nginx + PHP-FPM](<https://daemonless.io/images/logos/nginx-php-fpm.svg>) Nginx + PHP-FPM

[![Build Status](<https://img.shields.io/github/actions/workflow/status/daemonless/nginx-php-fpm/build.yaml?style=flat-square&label=Build&color=green>)](<https://github.com/daemonless/nginx-php-fpm/actions>) [![Last Commit](<https://img.shields.io/github/last-commit/daemonless/nginx-php-fpm?style=flat-square&label=Last+Commit&color=blue>)](<https://github.com/daemonless/nginx-php-fpm/commits>) [![OCI Pulls](<https://img.shields.io/docker/pulls/daemonless/nginx-php-fpm?style=flat-square&label=OCI+Pulls&color=blue>)](<https://hub.docker.com/r/daemonless/nginx-php-fpm>)

Nginx with PHP-FPM, composer and the PHP extensions from ports, for running your own PHP sites.

|  |  |
| --- | --- |
| **Port** | `80` |
| **Registry** | [`ghcr.io/daemonless/nginx-php-fpm`](<https://github.com/daemonless/nginx-php-fpm/pkgs/container/nginx-php-fpm>) |
| **Daemonless** | [daemonless/nginx-php-fpm](<https://github.com/daemonless/nginx-php-fpm>) |
| **Source** | [php/php-src](<https://github.com/php/php-src>) |
| **Website** | [www.php.net](<https://www.php.net/>) |

## Your site

Put your PHP code in `/config/www`. On first start, when that directory is empty, a welcome page is placed there showing the PHP version and the loaded extensions. `/config/nginx/site-confs/default.conf` serves it; add more files there for more sites. `/config/nginx/nginx.conf` and `/config/php/www.conf` hold the nginx main config and the php-fpm pool. All of these are copied in on first run and never overwritten afterwards.

## PHP settings

`/config/php/php-local.ini` is loaded after `php.ini` and holds the memory, upload and opcache settings. Edit it and restart the container.

## Extensions

The image ships every PHP extension in the FreeBSD ports tree except imagick, smbclient and enchant, whose dependencies would quadruple the image. By default these are enabled:

`apcu bcmath bz2 ctype curl dom exif fileinfo filter gd iconv intl mbstring mysqli opcache pdo pdo_mysql pdo_pgsql pdo_sqlite pgsql phar posix session simplexml tokenizer xml xmlreader xmlwriter zip zlib`

Set `PHP_EXTENSIONS` to replace that list, or `PHP_EXTENSIONS_EXTRA` to add to it, for example `PHP_EXTENSIONS_EXTRA=redis soap ldap`. Extensions not in the image are reported in the container log at start. json and openssl are built into PHP and always available.

## Composer

Composer is installed. Run it as the `bsd` user so the files it writes stay owned by your PUID:

```
podman exec -u bsd nginx-php-fpm composer install -d /config/www
```

## PHP versions

Tags `86`, `85` and `84` pick the PHP version; `latest` is PHP 8.5. Each has a `-pkg-latest` variant built from the FreeBSD latest package branch. Newer PHP versions ship fewer extensions until the pecl ports catch up; the welcome page lists what is loaded.

## Prerequisites

Before deploying, ensure your host environment is ready. See the [Quick Start Guide](<https://daemonless.io/guides/quick-start/index.md>) for host setup instructions, including the security model for host vs. container privileges.

## Deployment

**Customize Paths, UID & Ports**

Install and manage **Nginx + PHP-FPM** on FreeBSD with [fjord](<https://fjord.daemonless.io>):

```
fjord install nginx-php-fpm
```

Or open the **App Store** in the fjord web UI and install **Nginx + PHP-FPM** from the wizard. New to fjord? See the [Install Guide](<https://fjord.daemonless.io/install/>).

```
services:
  nginx-php-fpm:
    image: "ghcr.io/daemonless/nginx-php-fpm:latest"
    container_name: nginx-php-fpm
    environment:
      - PUID=1000  # User ID for php-fpm workers and nginx workers
      - PGID=1000  # Group ID for php-fpm workers and nginx workers
      - TZ=UTC  # Timezone, also used as PHP's date.timezone
      # - PHP_EXTENSIONS=  # Space-separated list of PHP extensions to enable; replaces the default set
      # - PHP_EXTENSIONS_EXTRA=  # Extensions to enable in addition to PHP_EXTENSIONS
    volumes:
      - "/containers/nginx-php-fpm:/config"
    ports:
      - "80:80"
    # always (not unless-stopped) so FreeBSD's podman rc.d auto-starts it at boot
    restart: always
```

Save as `compose.yaml`, then run `podman-compose up -d`.

> [!WARNING]
>
> Exposing ports in AppJail means that your service can be reached from remote hosts. If that is not your intention, do not expose the ports and communicate with the service using the jail's IPv4 address or hostname assigned by the virtual network.

```
# .env

DIRECTOR_PROJECT=nginx-php-fpm
PUID=1000
PGID=1000
TZ=UTC
```

```
# appjail-director.yml

options:
  - virtualnet: ':<random> default'
  - nat:
services:
  nginx-php-fpm:
    name: nginx_php_fpm
    options:
      - container: 'args:--pull'
      - expose: '80:80 proto:tcp'
    oci:
      user: root
      environment:
        - PUID: !ENV '${PUID}'
        - PGID: !ENV '${PGID}'
        - TZ: !ENV '${TZ}'
    volumes:
      - nginx-php-fpm: /config
volumes:
  nginx-php-fpm:
    device: '/containers/nginx-php-fpm'
```

```
# Makejail

ARG tag=latest

OPTION container=boot
OPTION overwrite=force
OPTION from=ghcr.io/daemonless/nginx-php-fpm:${tag}
```

Save the files above, then run `appjail-director up`.

> [!WARNING]
>
> **Experimental**
>
> Bastille's OCI support is experimental. It requires `buildah` and shares the host network stack (`inherit`). Mount volumes with `--volume HOST JAIL`; without it, image-declared volumes are stored under `${bastille_volumesdir}/${jail}`.

```
services:
  nginx-php-fpm:
    name: nginx-php-fpm
    image: "ghcr.io/daemonless/nginx-php-fpm:latest"
    network:
      - mode: host
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=UTC
    volumes:
      - "/containers/nginx-php-fpm:/config"
```

Save as `bastille-compose.yml`, then run `bastille up`.

Open `http://<server>:80` from another machine (the server's own browser can't use a published port).

## Parameters

### Environment Variables

| Variable | Default | Description |
| --- | --- | --- |
| `PUID` | `1000` | User ID for php-fpm workers and nginx workers |
| `PGID` | `1000` | Group ID for php-fpm workers and nginx workers |
| `TZ` | `UTC` | Timezone, also used as PHP's date.timezone |
| `PHP_EXTENSIONS` | \`\` | Space-separated list of PHP extensions to enable; replaces the default set |
| `PHP_EXTENSIONS_EXTRA` | \`\` | Extensions to enable in addition to PHP\_EXTENSIONS |

### Volumes

| Path | Description |
| --- | --- |
| `/config` | Web root (/config/www), nginx and PHP configuration |

### Ports

| Port | Protocol | Description |
| --- | --- | --- |
| `80` | TCP | Web |

## Version Tags

| Tag | Description | Best For |
| :--- | :--- | :--- |
| `85` / `85-pkg` / `latest` / `pkg` | **FreeBSD Quarterly**. Uses stable, tested packages. | Most users — recommended. |
| `85-pkg-latest` / `pkg-latest` | **FreeBSD Latest**. Rolling package updates. | Staying current. |
| `86` / `86-pkg` | **FreeBSD Quarterly**. Uses stable, tested packages. | Production stability. |
| `86-pkg-latest` | **FreeBSD Latest**. Rolling package updates. | Staying current. |
| `84` / `84-pkg` | **FreeBSD Quarterly**. Uses stable, tested packages. | Production stability. |
| `84-pkg-latest` | **FreeBSD Latest**. Rolling package updates. | Staying current. |

> [!NOTE]
>
> **Implementation Details**
>
> - **Architectures:** amd64
> - **User:** `bsd` (UID/GID set via [PUID/PGID](<https://daemonless.io/guides/permissions/index.md>)). Defaults to `1000:1000`.
> - **Base:** Built on `ghcr.io/daemonless/base` (FreeBSD 15.1).

---

Need help? Join our [Discord](<https://discord.gg/Kb9tkhecZT>) community.
