Caddy with cloudflare and php


I’have recently updated my caddy to the latest version (2.6). With that, alpine change the version of PHP from 7 to 8.
Before try to solve by my self why php7 doesn’t work and the listen of port 9000 fails, I searched on internet how to have caddy with PHP. I don’t found relevant information or only topics without solution.
So I have updated my files and share it with the community, hope that can help someone.


FROM caddy:2.6.4-builder-alpine AS builder

RUN xcaddy build \

FROM caddy:2.6.4-alpine AS caddyRun

ARG PUID="1000"
ARG PGID="1000"

RUN apk add --no-cache --update \
        openrc \
        php8 \
        php8-session \
        php8-curl \
        php8-json \
        php8-fpm \

RUN addgroup -g ${PGID} www-user && \
  adduser -D -H -u ${PUID} -G www-user www-user && \
  sed -i "s|^user = .*|user = www-user|g" /etc/php8/php-fpm.d/www.conf && \
  sed -i "s|^group = .*|group = www-user|g" /etc/php8/php-fpm.d/www.conf

COPY --from=builder /usr/bin/caddy /usr/bin/caddy


VOLUME /etc/caddy
VOLUME /data/caddy/certificates
VOLUME /app/

COPY /usr/local/bin/

RUN chmod +x /usr/local/bin/ \
    && ln -s /usr/local/bin/ /


php-fpm8 -D
caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

I don’t remember where I found the informations, due to I create these files some time ago. If you have sources or remarks, don’t hesitate to share it.

Best regards,

This post wasn’t a fit for the Showcase category, so I moved it to Help.

It sounds like the problems you’re experiencing have to do with Docker and PHP, not with Caddy in particular.

Running PHP and Caddy in one container like that is a bad idea. Your script does not properly take care of handling signals to gracefully shut down the programs. I suggest using something like GitHub - Baldinof/caddy-supervisor: Run and supervise background processes from Caddy instead.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.