diff --git a/.travis.yml b/.travis.yml index 5f4188e..bb4e989 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ services: env: global: - COMMIT=${TRAVIS_COMMIT::8} - - REPO=trafex/php-nginx + - REPO=trafex/alpine-nginx-php7 script: - docker --version diff --git a/Dockerfile b/Dockerfile index 400e96f..fccb0e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,17 @@ -FROM php:7.0-fpm +FROM alpine:latest -# Install Nginx -ENV NGINX_VERSION 1.9.11-1~jessie - -RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \ - && echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list \ - && apt-get update \ - && apt-get install -y ca-certificates nginx=${NGINX_VERSION} gettext-base \ - && rm -rf /var/lib/apt/lists/* - -# Install supervisor -RUN apt-get update && apt-get install -y supervisor +# Install packages +RUN apk --update add php7-fpm nginx supervisor --repository http://nl.alpinelinux.org/alpine/edge/testing/ # Configure nginx -RUN rm /etc/nginx/conf.d/default.conf -COPY config/nginx.conf /etc/nginx/conf.d/nginx.conf - -# Configure supervisor -COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY config/nginx.conf /etc/nginx/nginx.conf # Configure PHP-FPM -COPY config/php.ini /usr/local/etc/php/conf.d/custom.ini +COPY config/fpm-pool.conf /etc/php7/php-fpm.d/zzz_custom.conf +COPY config/php.ini /etc/php7/conf.d/zzz_custom.ini + +# Configure supervisord +COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf # Add application RUN mkdir -p /var/www/html @@ -28,4 +19,4 @@ WORKDIR /var/www/html COPY src/ /var/www/html/ EXPOSE 80 443 -CMD ["/usr/bin/supervisord"] +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/README.md b/README.md index 12ff015..f890f40 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -Docker PHP-FPM 7.0 & Nginx 1.9 setup -==================================== -Example PHP-FPM 7.0 & Nginx 1.9 setup for Docker +Docker PHP-FPM 7.0 & Nginx 1.8 on Alpine Linux +============================================== +Example PHP-FPM 7.0 & Nginx 1.8 setup for Docker, build on [Alpine Linux](http://www.alpinelinux.org/). +The image is only +/- 60MB large. -[![Docker Pulls](https://img.shields.io/docker/pulls/trafex/php-nginx.svg)](https://hub.docker.com/r/trafex/php-nginx/) - +[![Docker Pulls](https://img.shields.io/docker/pulls/trafex/alpine-nginx-php7.svg)](https://hub.docker.com/r/trafex/alpine-nginx-php7/) Usage ----- diff --git a/config/fpm-pool.conf b/config/fpm-pool.conf new file mode 100644 index 0000000..a6b1598 --- /dev/null +++ b/config/fpm-pool.conf @@ -0,0 +1,28 @@ +[www] +; Enable status page +pm.status_path = /fpm-status + +; Ondemand process manager +pm = ondemand + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. +; This value sets the limit on the number of simultaneous requests that will be +; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. +; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP +; CGI. The below defaults are based on a server without much resources. Don't +; forget to tweak pm.* to fit your needs. +; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' +; Note: This value is mandatory. +pm.max_children = 50 + +; The number of seconds after which an idle process will be killed. +; Note: Used only when pm is set to 'ondemand' +; Default Value: 10s +pm.process_idle_timeout = 10s; + +; The number of requests each child process should execute before respawning. +; This can be useful to work around memory leaks in 3rd party libraries. For +; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. +; Default Value: 0 +pm.max_requests = 500 diff --git a/config/nginx.conf b/config/nginx.conf index 3d7cb87..92f2e22 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -1,49 +1,62 @@ -server { - listen [::]:80 default_server; - listen 80 default_server; - server_name _; +worker_processes 1; - sendfile off; +events { + worker_connections 1024; +} - root /var/www/html; - index index.php index.html; +http { + include mime.types; + default_type application/octet-stream; - error_log /dev/stderr info; - access_log /dev/stdout; + keepalive_timeout 65; - location / { - # First attempt to serve request as file, then - # as directory, then fall back to index.php - try_files $uri $uri/ /index.php?q=$uri&$args; - } + server { + listen [::]:80 default_server; + listen 80 default_server; + server_name _; - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } + sendfile off; - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - location ~ \.php$ { - try_files $uri =404; - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass localhost:9000; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param SCRIPT_NAME $fastcgi_script_name; - fastcgi_index index.php; - include fastcgi_params; - } + root /var/www/html; + index index.php index.html; - location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { - expires 5d; - } + error_log /dev/stderr info; + access_log /dev/stdout; - # deny access to . files, for security - # - location ~ /\. { - log_not_found off; - deny all; + location / { + # First attempt to serve request as file, then + # as directory, then fall back to index.php + try_files $uri $uri/ /index.php?q=$uri&$args; + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass localhost:9000; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + fastcgi_index index.php; + include fastcgi_params; + } + + location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { + expires 5d; + } + + # deny access to . files, for security + # + location ~ /\. { + log_not_found off; + deny all; + } } } diff --git a/config/supervisord.conf b/config/supervisord.conf index 18e1ab8..d8886a4 100644 --- a/config/supervisord.conf +++ b/config/supervisord.conf @@ -2,7 +2,7 @@ nodaemon=true [program:php-fpm] -command=php-fpm +command=php-fpm7 -F stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr