Last active
February 13, 2024 22:52
-
-
Save Baldinof/8af17f09c7a57aa468e1b6c66d4272a3 to your computer and use it in GitHub Desktop.
Single PHP FPM container with Caddy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/vendor | |
/docker | |
/Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0.0.0.0:{$PORT} | |
root /usr/src/app/public | |
fastcgi / /var/run/php-fpm.sock php | |
rewrite { | |
to {path} /index.php?{query} | |
} | |
supervisor { | |
command php-fpm | |
restart_policy always | |
redirect_stdout stdout | |
redirect_stderr stderr | |
} | |
errors stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:7.4-fpm-alpine | |
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer | |
COPY --from=wizbii/caddy /caddy /usr/local/bin/caddy | |
RUN apk add --no-cache autoconf openssl-dev g++ make pcre-dev icu-dev zlib-dev libzip-dev && \ | |
docker-php-ext-install bcmath intl opcache zip sockets && \ | |
apk del --purge autoconf g++ make && \ | |
mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" | |
WORKDIR /usr/src/app | |
COPY composer.json composer.lock ./ | |
RUN composer install --no-dev --optimize-autoloader --no-scripts --no-plugins --prefer-dist --no-progress --no-interaction | |
COPY . . | |
ENV APP_ENV=prod | |
ENV PORT=80 | |
RUN caddy -validate -conf=docker/Caddyfile && \ | |
cp docker/php-fpm.conf /usr/local/etc/php-fpm.d/zz-docker.conf && \ | |
php bin/console cache:warmup && \ | |
chmod -R 777 var/cache var/log | |
EXPOSE 80 | |
CMD ["caddy", "--conf", "docker/Caddyfile", "--log", "stdout"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[global] | |
daemonize = no | |
[www] | |
listen = /var/run/php-fpm.sock |
This is caddy that is starting php-fpm, using it's supervisor plugin.
If you are using Caddy V2, I recommend you to have a look at this gist: https://gist.github.com/Baldinof/9adf039d9edabc0001dea3abafb6764f
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The command
php bin/console cache:warmup
at the RUN keywordit is running using an UNIX socket file
/var/run/php-fpm.sock