├── Makefile ├── README.md └── build ├── Dockerfile-nginx ├── Dockerfile-ppm ├── Dockerfile-standalone ├── etc ├── nginx.conf ├── nginx_default.conf ├── php-opcache.ini └── php.ini ├── run-nginx.sh ├── run-ppm.sh └── run-standalone.sh /Makefile: -------------------------------------------------------------------------------- 1 | VERSION?=dev-master 2 | HTTP_VERSION?=dev-master 3 | TAG?=latest 4 | 5 | # example: 6 | # $ make VERSION=dev-master TAG=latest nginx 7 | # $ make TAG=latest push-all 8 | 9 | .PHONY: default nginx ppm standalone push-all 10 | 11 | default: nginx ppm standalone 12 | 13 | nginx: 14 | docker build -t phppm/nginx:${TAG} -f build/Dockerfile-nginx build/ --build-arg version=${VERSION} --build-arg http_version=${HTTP_VERSION} 15 | docker tag phppm/nginx:${TAG} phppm/nginx:latest 16 | 17 | ppm: 18 | docker build -t phppm/ppm:${TAG} -f build/Dockerfile-ppm build/ --build-arg version=${VERSION} --build-arg http_version=${HTTP_VERSION} 19 | docker tag phppm/ppm:${TAG} phppm/ppm:latest 20 | 21 | standalone: 22 | docker build -t phppm/standalone:${TAG} -f build/Dockerfile-standalone build/ --build-arg version=${VERSION} --build-arg http_version=${HTTP_VERSION} 23 | docker tag phppm/standalone:${TAG} phppm/standalone:latest 24 | 25 | push-all: 26 | docker push phppm/nginx:${TAG} 27 | docker push phppm/standalone:${TAG} 28 | docker push phppm/ppm:${TAG} 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP-PM Docker 2 | 3 | You can use [PHP-PM](https://github.com/php-pm/php-pm) using Docker. We provide you several images always with PHP-PM and PHP7 pre-installed. 4 | 5 | ## Images 6 | 7 | - [`phppm/nginx`](https://hub.docker.com/r/phppm/nginx/): Contains php-pm and uses NGiNX as static file serving 8 | - [`phppm/standalone`](https://hub.docker.com/r/phppm/standalone/): Contains php-pm and uses php-pm's ability to serve static files (slower) 9 | - [`phppm/ppm`](https://hub.docker.com/r/phppm/ppm/): Just the php-pm binary as entry point 10 | 11 | ### Examples 12 | 13 | ``` 14 | # change into your project folder first 15 | cd your/symfony-project/ 16 | 17 | # see what php-pm binary can do for you. 18 | $ docker run -v `pwd`:/var/www/ phppm/ppm --help 19 | $ docker run -v `pwd`:/var/www/ phppm/ppm config --help 20 | 21 | # with nginx as static file server 22 | $ docker run -v `pwd`:/var/www -p 8080:80 phppm/nginx 23 | 24 | # with php-pm as static file server (dev only) 25 | $ docker run -v `pwd`:/var/www -p 8080:80 phppm/standalone 26 | 27 | # use `PPM_CONFIG` environment variable to choose a different ppm config file. 28 | $ docker run -v `pwd`:/var/www -p 80:80 phppm/nginx -c ppm-prod.json 29 | 30 | # enable file tracking, to automatically restart ppm when php source changed 31 | $ docker run -v `pwd`:/var/www -p 80:80 phppm/nginx --debug=1 --app-env=dev 32 | 33 | # change static file directory. PPM_STATIC relative to mounted /var/www/. 34 | $ docker run -v `pwd`:/var/www -p 80:80 phppm/nginx --static-directory=web/ 35 | 36 | # Use 16 threads/workers for PHP-PM. 37 | $ docker run -v `pwd`:/var/www -p 80:80 phppm/nginx --workers=16 38 | ``` 39 | 40 | Docker compose 41 | 42 | ``` 43 | version: "3.1" 44 | 45 | services: 46 | ppm: 47 | image: phppm/nginx 48 | command: --debug=1 --app-env=dev --static-directory=web/ 49 | volumes: 50 | - ./symfony-app/:/var/www 51 | ports: 52 | - "80:80" 53 | ``` 54 | 55 | ### Configuration 56 | 57 | You should configure PPM via the ppm.json in the root directory, which is within the container mounted to 58 | `/var/www/`. Alternatively, you can overwrite each option using the regular cli arguments. 59 | 60 | ``` 61 | # change the ppm.json within current directory 62 | docker run -v `pwd`:/var/www phppm/ppm config --help 63 | 64 | # not persisting config changes 65 | docker run -v `pwd`:/var/www -p 80:80 phppm/nginx --help 66 | docker run -v `pwd`:/var/www -p 80:80 phppm/nginx --workers=1 --debug 1 67 | docker run -v `pwd`:/var/www -p 80:80 phppm/nginx --c prod-ppm.json 68 | ``` 69 | 70 | ## Build image with own tools/dependencies 71 | 72 | If your applications requires additional php modules or other tools and libraries in your container, you 73 | can use our image as base. We use lightweight Alpine Linux. 74 | 75 | ``` 76 | # Dockerfile 77 | FROM phppm/nginx:1.0 78 | 79 | RUN apk --no-cache add git 80 | RUN apk --no-cache add ca-certificates wget 81 | 82 | # whatever you need 83 | ``` 84 | 85 | ``` 86 | docker build vendor/my-image -f Dockerfile . 87 | # now use vendor/my-image instead of `phppm/nginx` 88 | ``` 89 | -------------------------------------------------------------------------------- /build/Dockerfile-nginx: -------------------------------------------------------------------------------- 1 | FROM composer:1.9 as composer 2 | 3 | ARG version=dev-master 4 | ARG http_version=dev-master 5 | RUN mkdir /ppm && cd /ppm && composer require php-pm/php-pm:${version} && composer require php-pm/httpkernel-adapter:${http_version} 6 | 7 | FROM alpine:3.11 8 | 9 | ENV LC_ALL en_US.UTF-8 10 | ENV LANG en_US.UTF-8 11 | 12 | RUN apk --no-cache add tzdata && \ 13 | cp /usr/share/zoneinfo/Etc/UTC /etc/localtime && \ 14 | echo "UTC" | tee /etc/timezone && \ 15 | apk del tzdata 16 | 17 | RUN apk --no-cache add \ 18 | php7 php7-opcache php7-fpm php7-cgi php7-ctype php7-json php7-dom php7-zip php7-zip php7-gd \ 19 | php7-curl php7-mbstring php7-redis php7-mcrypt php7-iconv php7-posix php7-pdo_mysql php7-tokenizer php7-simplexml php7-session \ 20 | php7-xml php7-sockets php7-openssl php7-fileinfo php7-ldap php7-exif php7-pcntl php7-xmlwriter php7-phar php7-zlib \ 21 | php7-intl 22 | ADD etc/php.ini /etc/php7/php.ini 23 | 24 | RUN apk --no-cache add bash 25 | 26 | RUN apk --no-cache add nginx 27 | ADD etc/nginx_default.conf /etc/nginx/sites-enabled/default 28 | ADD etc/nginx.conf /etc/nginx/nginx.conf 29 | 30 | EXPOSE 80 31 | 32 | COPY --from=composer /ppm /ppm 33 | 34 | WORKDIR /var/www 35 | 36 | ADD run-nginx.sh /etc/app/run.sh 37 | ENTRYPOINT ["/bin/bash", "/etc/app/run.sh"] 38 | -------------------------------------------------------------------------------- /build/Dockerfile-ppm: -------------------------------------------------------------------------------- 1 | FROM composer:1.9 as composer 2 | 3 | ARG version=dev-master 4 | ARG http_version=dev-master 5 | RUN mkdir /ppm && cd /ppm && composer require php-pm/php-pm:${version} && composer require php-pm/httpkernel-adapter:${http_version} 6 | 7 | FROM alpine:3.11 8 | 9 | ENV LC_ALL en_US.UTF-8 10 | ENV LANG en_US.UTF-8 11 | 12 | RUN apk --no-cache add tzdata && \ 13 | cp /usr/share/zoneinfo/Etc/UTC /etc/localtime && \ 14 | echo "UTC" | tee /etc/timezone && \ 15 | apk del tzdata 16 | 17 | RUN apk --no-cache add \ 18 | php7 php7-opcache php7-fpm php7-cgi php7-ctype php7-json php7-dom php7-zip php7-zip php7-gd \ 19 | php7-curl php7-mbstring php7-redis php7-mcrypt php7-iconv php7-posix php7-pdo_mysql php7-tokenizer php7-simplexml php7-session \ 20 | php7-xml php7-sockets php7-openssl php7-fileinfo php7-ldap php7-exif php7-pcntl php7-xmlwriter php7-phar php7-zlib \ 21 | php7-intl 22 | ADD etc/php.ini /etc/php7/php.ini 23 | 24 | RUN apk --no-cache add bash 25 | 26 | EXPOSE 80 27 | 28 | COPY --from=composer /ppm /ppm 29 | 30 | WORKDIR /var/www 31 | 32 | ADD run-ppm.sh /etc/app/run.sh 33 | ENTRYPOINT ["/bin/sh", "/etc/app/run.sh"] 34 | -------------------------------------------------------------------------------- /build/Dockerfile-standalone: -------------------------------------------------------------------------------- 1 | FROM composer:1.9 as composer 2 | 3 | ARG version=dev-master 4 | ARG http_version=dev-master 5 | RUN mkdir /ppm && cd /ppm && composer require php-pm/php-pm:${version} && composer require php-pm/httpkernel-adapter:${http_version} 6 | 7 | FROM alpine:3.11 8 | 9 | ENV LC_ALL en_US.UTF-8 10 | ENV LANG en_US.UTF-8 11 | 12 | RUN apk --no-cache add tzdata && \ 13 | cp /usr/share/zoneinfo/Etc/UTC /etc/localtime && \ 14 | echo "UTC" | tee /etc/timezone && \ 15 | apk del tzdata 16 | 17 | RUN apk --no-cache add \ 18 | php7 php7-opcache php7-fpm php7-cgi php7-ctype php7-json php7-dom php7-zip php7-zip php7-gd \ 19 | php7-curl php7-mbstring php7-redis php7-mcrypt php7-iconv php7-posix php7-pdo_mysql php7-tokenizer php7-simplexml php7-session \ 20 | php7-xml php7-sockets php7-openssl php7-fileinfo php7-ldap php7-exif php7-pcntl php7-xmlwriter php7-phar php7-zlib \ 21 | php7-intl 22 | ADD etc/php.ini /etc/php7/php.ini 23 | 24 | RUN apk --no-cache add bash 25 | 26 | EXPOSE 80 27 | 28 | COPY --from=composer /ppm /ppm 29 | 30 | WORKDIR /var/www 31 | 32 | ADD run-standalone.sh /etc/app/run.sh 33 | ENTRYPOINT ["/bin/bash", "/etc/app/run.sh"] 34 | -------------------------------------------------------------------------------- /build/etc/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes auto; 2 | pid /run/nginx.pid; 3 | 4 | daemon on; 5 | 6 | events { 7 | worker_connections 768; 8 | # multi_accept on; 9 | } 10 | 11 | http { 12 | ## 13 | # Basic Settings 14 | ## 15 | 16 | sendfile on; 17 | tcp_nopush on; 18 | tcp_nodelay on; 19 | keepalive_timeout 65; 20 | types_hash_max_size 2048; 21 | # server_tokens off; 22 | 23 | # server_names_hash_bucket_size 64; 24 | # server_name_in_redirect off; 25 | 26 | include /etc/nginx/mime.types; 27 | default_type application/octet-stream; 28 | 29 | ## 30 | # SSL Settings 31 | ## 32 | 33 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE 34 | ssl_prefer_server_ciphers on; 35 | 36 | ## 37 | # Logging Settings 38 | ## 39 | 40 | access_log /var/log/nginx/access.log; 41 | error_log /var/log/nginx/error.log; 42 | 43 | proxy_buffering off; 44 | 45 | ## 46 | # Gzip Settings 47 | ## 48 | gzip off; 49 | gzip_disable "msie6"; 50 | 51 | # gzip_vary on; 52 | # gzip_proxied any; 53 | # gzip_comp_level 6; 54 | # gzip_buffers 16 8k; 55 | # gzip_http_version 1.1; 56 | # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; 57 | 58 | ## 59 | # Virtual Host Configs 60 | ## 61 | 62 | include /etc/nginx/sites-enabled/*; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /build/etc/nginx_default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name _; 4 | root STATIC_DIRECTORY; 5 | 6 | client_max_body_size 1000m; 7 | 8 | location / { 9 | try_files $uri @ppm; 10 | } 11 | 12 | location @ppm { 13 | proxy_set_header Host $http_host; 14 | proxy_set_header X-Real-IP $remote_addr; 15 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 16 | proxy_set_header X-Forwarded-Proto $scheme; 17 | proxy_pass http://127.0.0.1:8080; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /build/etc/php-opcache.ini: -------------------------------------------------------------------------------- 1 | zend_extension=opcache.so 2 | 3 | opcache.max_accelerated_files = 10000 4 | opcache.memory_consumption = 256 5 | opcache.interned_string_buffer = 16 6 | -------------------------------------------------------------------------------- /build/etc/php.ini: -------------------------------------------------------------------------------- 1 | date.timezone = UTC 2 | memory_limit = -1 3 | 4 | disable_functions = 5 | 6 | max_execution_time = 0 7 | max_input_time = 0 8 | -------------------------------------------------------------------------------- /build/run-nginx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | trapIt () { "$@"& pid="$!"; for SGNL in INT TERM CHLD USR1; do trap "kill -$SGNL $pid" "$SGNL"; done; while kill -0 $pid > /dev/null 2>&1; do wait $pid; ec="$?"; done; exit $ec; }; 4 | 5 | STATIC=/var/www/ 6 | args=" $@ " 7 | if [[ ! $args =~ " --help " ]]; then 8 | ARG_STATIC=`/ppm/vendor/bin/ppm config --show-option="static-directory" "$@"` 9 | fi 10 | 11 | [ ! -z "$ARG_STATIC" ] && STATIC="${STATIC}${ARG_STATIC}" 12 | sed -i "s#STATIC_DIRECTORY#${STATIC}#g" /etc/nginx/sites-enabled/default 13 | 14 | nginx 15 | 16 | mkdir -p /ppm/run 17 | chmod -R 777 /ppm/run 18 | ARGS='--port=8080 --socket-path=/ppm/run --pidfile=/ppm/ppm.pid' 19 | 20 | # make sure static-directory is not served by php-pm 21 | ARGS="$ARGS --static-directory=''" 22 | 23 | trapIt /ppm/vendor/bin/ppm start --ansi $ARGS $@ 24 | -------------------------------------------------------------------------------- /build/run-ppm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | trapIt () { "$@"& pid="$!"; for SGNL in INT TERM CHLD USR1; do trap "kill -$SGNL $pid" "$SGNL"; done; while kill -0 $pid > /dev/null 2>&1; do wait $pid; ec="$?"; done; exit $ec; }; 4 | 5 | trapIt /ppm/vendor/bin/ppm --ansi "$@" 6 | -------------------------------------------------------------------------------- /build/run-standalone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | trapIt () { "$@"& pid="$!"; for SGNL in INT TERM CHLD USR1; do trap "kill -$SGNL $pid" "$SGNL"; done; while kill -0 $pid > /dev/null 2>&1; do wait $pid; ec="$?"; done; exit $ec; }; 4 | 5 | ARGS='--port 80' 6 | trapIt /ppm/vendor/bin/ppm start --ansi $ARGS $@ 7 | --------------------------------------------------------------------------------