├── .gitignore ├── php-fpm-wrapper.sh ├── Caddyfile ├── README.md └── Dockerfile /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /php-fpm-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if [ ! -z "$PHP_BEFORE" ]; then 4 | eval $PHP_BEFORE 5 | fi 6 | 7 | if [ -f /srv/composer.lock ]; then 8 | cd /srv 9 | composer install ${PHP_COMPOSER_FLAGS} 10 | fi 11 | 12 | php-fpm7 13 | 14 | if [ ! -z "$PHP_AFTER" ]; then 15 | eval $PHP_AFTER 16 | fi 17 | -------------------------------------------------------------------------------- /Caddyfile: -------------------------------------------------------------------------------- 1 | 0.0.0.0:80, 0.0.0.0:443 { 2 | 3 | log stdout 4 | errors stderr 5 | gzip 6 | 7 | root /srv/ 8 | 9 | fastcgi / 127.0.0.1:9000 php 10 | 11 | # only rewrite paths with no file extension (/) or that has .php extension 12 | rewrite { 13 | ext / .php 14 | to {path} {path}/ /index.php?{query} 15 | } 16 | 17 | errors { 18 | log stdout 19 | 400 _blank.html 20 | 401 _blank.html 21 | 402 _blank.html 22 | 403 _blank.html 23 | 404 _blank.html 24 | 405 _blank.html 25 | 406 _blank.html 26 | 407 _blank.html 27 | 408 _blank.html 28 | 409 _blank.html 29 | 410 _blank.html 30 | 418 _blank.html 31 | 420 _blank.html 32 | 426 _blank.html 33 | 428 _blank.html 34 | 429 _blank.html 35 | 500 _blank.html 36 | 501 _blank.html 37 | 502 _blank.html 38 | 503 _blank.html 39 | 504 _blank.html 40 | 505 _blank.html 41 | 508 _blank.html 42 | 510 _blank.html 43 | 598 _blank.html 44 | 599 _blank.html 45 | } 46 | 47 | startup php-fpm-wrapper 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Caddy Server with PHP-FPM 2 | 3 | [![](https://images.microbadger.com/badges/image/stevepacker/caddy-php7.svg)](https://microbadger.com/images/stevepacker/caddy-php7 "Get your own image badge on microbadger.com") 4 | 5 | This creates a Docker container running PHP on Alpine Linux. 6 | 7 | ## Why another container? 8 | 9 | I just wanted all the PHP libraries I tend to use. 10 | 11 | It also supports running commands before and after starting PHP-FPM and running 12 | `composer install` before running PHP-FPM. 13 | 14 | It also includes the (https://wiki.archlinux.org/index.php/SSMTP)[ssmtp] package so that after its configured you can use PHP's mail() function. 15 | 16 | ## Run Example 17 | 18 | - `docker run -p 80:80 -p 443:443 -v /var/www/html:/srv stevepacker/caddy-php7` 19 | 20 | 21 | ## Docker Environment Variables 22 | 23 | - `PHP_BEFORE`: command(s) to run prior to running `composer install` and `php-fpm` 24 | - `PHP_COMPOSER_FLAGS`: flags to include with `composer install` (ex: --prefer-dist --no-dev) 25 | - `PHP_AFTER`: command(s) to run after `composer install` and `php-fpm` 26 | 27 | ## Docker Volumes 28 | 29 | - `/srv`: Base directory. If a `composer.lock` is in this directory, 30 | `composer install` will automatically run prior to starting `php-fpm` 31 | - `/root/.caddy`: When an SSL is generated, files are stored here by Caddy. 32 | - `/etc/Caddyfile`: If you intend to include your own Caddyfile, mount it here. 33 | - `/etc/ssmtp/ssmtp.conf `: If you intend to use PHP's mail() function, configure this file. 34 | - `/etc/ssmtp/revaliases`: Another configuration file for ssmtp 35 | 36 | ## Caddy Extensions: 37 | 38 | - git 39 | - ipfilter 40 | 41 | ## PHP Extensions: 42 | 43 | - composer 44 | - php7-fpm 45 | - ... and a bunch of others. Read the Dockerfile. 46 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:edge 2 | MAINTAINER Stephen Packer 3 | 4 | EXPOSE 80 443 5 | 6 | ENTRYPOINT ["/sbin/tini", "--"] 7 | 8 | ENV PHP_BEFORE= \ 9 | PHP_AFTER= \ 10 | PHP_COMPOSER_FLAGS= 11 | 12 | # install php and other libraries 13 | RUN echo "http://dl-3.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories \ 14 | && apk --no-cache add openssl git tar curl tini ssmtp \ 15 | php7-bcmath \ 16 | php7-bz2 \ 17 | php7-ctype \ 18 | php7-curl \ 19 | php7-dom \ 20 | php7-fpm \ 21 | php7-gd \ 22 | php7-iconv \ 23 | php7-imap \ 24 | php7-intl \ 25 | php7-json \ 26 | php7-mcrypt \ 27 | php7-mbstring \ 28 | php7-mongodb \ 29 | php7-openssl \ 30 | php7-pcntl \ 31 | php7-pdo_mysql \ 32 | php7-pdo_sqlite \ 33 | php7-phar \ 34 | php7-posix \ 35 | php7-redis \ 36 | php7-session \ 37 | php7-sockets \ 38 | php7-zlib \ 39 | && rm -rf /var/cache/apk/* \ 40 | && ln -s /usr/bin/php7 /usr/local/bin/php \ 41 | && echo "clear_env = no" >> /etc/php7/php-fpm.conf \ 42 | && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ 43 | # I use Yii2 a lot, and it uses this composer library 44 | && composer global require "fxp/composer-asset-plugin:^1.2.0" \ 45 | && adduser -SDHu 1000 php \ 46 | && sed -i "s/user *=.*$/user = php/" /etc/php7/php-fpm.conf \ 47 | && mkdir -p /srv \ 48 | && printf "" > /srv/index.php \ 49 | # caddy 50 | && wget -O - "http://caddyserver.com/download/build?os=linux&arch=amd64&features=git,ipfilter,jwt,realip" | tar xvz caddy \ 51 | && mv /caddy /usr/local/bin/caddy 52 | 53 | COPY Caddyfile /etc/Caddyfile 54 | COPY php-fpm-wrapper.sh /usr/local/bin/php-fpm-wrapper 55 | 56 | VOLUME ["/root/.caddy", "/srv"] 57 | 58 | CMD ["/usr/local/bin/caddy", "-conf=/etc/Caddyfile", "-agree"] 59 | --------------------------------------------------------------------------------