Caddy with cloudflare and php

Hello,

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.

Dockerfile

FROM caddy:2.6.4-builder-alpine AS builder

RUN xcaddy build \
        --with github.com/caddy-dns/cloudflare


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 \
        curl


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

EXPOSE 80
EXPOSE 443
EXPOSE 2019


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

COPY run.sh /usr/local/bin/

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

ENTRYPOINT [ "run.sh" ]

run.sh

#!/bin/sh
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,
Adri

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 run.sh 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.