├── .gitignore ├── LICENSE.txt ├── README.md ├── appphp ├── .dockerignore ├── Dockerfile └── phpinfo.php ├── docker-compose.yml ├── k8s-php-thinkphp-hello.yml ├── openresty ├── Dockerfile ├── README.md ├── nginx.conf └── sites │ ├── app.conf.example │ ├── default.conf.example │ ├── k8s-php-thinkphp-hello.conf │ └── laravel.conf.example └── php-fpm ├── Dockerfile ├── mysql.ini ├── opcache.ini ├── phpext.ini └── xweb.pool.conf /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwek/k8s-php-thinkphp-hello/ce1a8d9e9c79a527a389499ee6c232e933ea558a/.gitignore -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache Licence是著名的非盈利开源组织Apache采用的协议。 2 | 该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, 3 | 允许代码修改,再作为开源或商业软件发布。需要满足 4 | 的条件: 5 | 1. 需要给代码的用户一份Apache Licence ; 6 | 2. 如果你修改了代码,需要在被修改的文件中说明; 7 | 3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 8 | 带有原来代码中的协议,商标,专利声明和其他原来作者规 9 | 定需要包含的说明; 10 | 4. 如果再发布的产品中包含一个Notice文件,则在Notice文 11 | 件中需要带有本协议内容。你可以在Notice中增加自己的 12 | 许可,但不可以表现为对Apache Licence构成更改。 13 | 具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # k8s-php-thinkphp-hello 2 | 3 | 一个以php框架thinkphp的php项目,在kubernets上采用多容器在一个Pod的部署范例 4 | 5 | Docker镜像支持同时部署到kubernets或者docker-compose 6 | 7 | dockerfile 和 yaml文件 https://github.com/wwek/k8s-php-thinkphp-hello 8 | 9 | docker iamges仓库 https://hub.docker.com/r/wwek/k8s-php-thinkphp-hello/ 10 | 11 | 12 | ## kubernets(k8s)部署运行 13 | ``` 14 | kubectl apply -f k8s-php-thinkphp-hello.yml 15 | kubectl get pods |grep k8s-php-thinkphp-hello 16 | kubectl get service |grep k8s-php-thinkphp-hello 17 | kubectl get ingress |grep k8s-php-thinkphp-hello 18 | ``` 19 | 20 | 把 k8sphpthinkphp.com hosts解析到Ingress 的ip 21 | 22 | 然后浏览器 23 | 24 | 访问 http://k8sphpthinkphp.com/ 可以看到thinkphp的欢迎页面 25 | 26 | 访问 http://k8sphpthinkphp.com/phpinfo.php 可以看到phpinfo信息 27 | 28 | 如果没有ingress请自行修改service的type为 NodePort 使用节点的ip和端口访问 29 | 30 | ## docker-compose部署运行 31 | 32 | ### 直接up方式,直接pull已经build好的docker images 33 | ``` 34 | docker-compose up -d 35 | ``` 36 | 37 | ### 本地build方式 38 | ``` 39 | docker-compose up -d --build 40 | ``` 41 | 浏览器 42 | 访问 http://127.0.0.1 43 | 访问 http://127.0.0.1/phpinfo.php 44 | 45 | 46 | ## 特性 47 | * 组织的容器支持docker-compose部署 48 | * 组织的容器支持kubernets部署 49 | * 以php框架thinkphp为示例,演示php项目的kubernets部署 50 | * 多容器方式(3容器)分别为:appphp(php代码)、openresty(nginx webserver),php-fpm(php的运行环境) 51 | -------------------------------------------------------------------------------- /appphp/.dockerignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwek/k8s-php-thinkphp-hello/ce1a8d9e9c79a527a389499ee6c232e933ea558a/appphp/.dockerignore -------------------------------------------------------------------------------- /appphp/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM busybox:latest 2 | 3 | # 环境变量 4 | ENV APPROOT="/var/www/k8s-php-thinkphp-hello/" \ 5 | MYSQL_HOSTNAME= \ 6 | MYSQL_USERNAME= \ 7 | MYSQL_PASSWORD= 8 | 9 | # app预处理 10 | RUN mkdir -p $APPROOT 11 | 12 | # 配置 13 | WORKDIR $APPROOT 14 | 15 | # 安装Thinkphp5.1框架 16 | ARG TP_VERSION=5.1.8 17 | RUN wget -c https://github.com/top-think/framework/archive/v${TP_VERSION}.zip -O tpfw${TP_VERSION}.zip \ 18 | && unzip tpfw${TP_VERSION}.zip && mv framework-${TP_VERSION} thinkphp \ 19 | && wget -c https://github.com/top-think/think/archive/v${TP_VERSION}.zip -O tp${TP_VERSION}.zip \ 20 | && unzip tp${TP_VERSION}.zip && mv think-${TP_VERSION}/* ./ 21 | 22 | ADD ./phpinfo.php $APPROOT/public 23 | 24 | # 挂载 25 | VOLUME $APPROOT 26 | 27 | # 入口 28 | CMD ["sh"] -------------------------------------------------------------------------------- /appphp/phpinfo.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | 5 | ### Applications Code Container ############################# 6 | 7 | appphp: 8 | image: wwek/k8s-php-thinkphp-hello:app-v1 9 | build: 10 | context: ./appphp 11 | dockerfile: "Dockerfile" 12 | 13 | ### PHP-FPM Container ####################################### 14 | 15 | php-fpm: 16 | image: wwek/k8s-php-thinkphp-hello:php-fpm-7.2 17 | build: 18 | context: ./php-fpm 19 | dockerfile: "Dockerfile" 20 | volumes_from: 21 | - appphp 22 | environment: 23 | - RUN_MODE=prd 24 | - MYSQL_HOSTNAME= \ 25 | - MYSQL_USERNAME= \ 26 | - MYSQL_PASSWORD= 27 | depends_on: 28 | - appphp 29 | expose: 30 | - "9000" 31 | networks: 32 | - backend 33 | 34 | ### OPENRESTY Server Container ################################## 35 | 36 | openresty: 37 | image: wwek/k8s-php-thinkphp-hello:openresty 38 | build: 39 | context: ./openresty 40 | dockerfile: "Dockerfile" 41 | volumes_from: 42 | - appphp 43 | ports: 44 | - "80:80" 45 | - "443:443" 46 | depends_on: 47 | - php-fpm 48 | networks: 49 | - frontend 50 | - backend 51 | 52 | ### Networks Setup ############################################ 53 | 54 | networks: 55 | frontend: 56 | driver: "bridge" 57 | backend: 58 | driver: "bridge" 59 | 60 | ### Volumes Setup ############################################# 61 | 62 | volumes: 63 | redis: 64 | driver: "local" 65 | 66 | -------------------------------------------------------------------------------- /k8s-php-thinkphp-hello.yml: -------------------------------------------------------------------------------- 1 | # Service 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: k8s-php-thinkphp-hello 6 | labels: 7 | app: k8s-php-thinkphp-hello 8 | spec: 9 | type: ClusterIP 10 | ports: 11 | - port: 80 12 | targetPort: http 13 | protocol: TCP 14 | name: http 15 | selector: 16 | app: k8s-php-thinkphp-hello 17 | --- 18 | # deployment 19 | apiVersion: apps/v1beta2 20 | kind: Deployment 21 | metadata: 22 | name: k8s-php-thinkphp-hello 23 | labels: 24 | app: k8s-php-thinkphp-hello 25 | spec: 26 | replicas: 1 27 | selector: 28 | matchLabels: 29 | app: k8s-php-thinkphp-hello 30 | template: 31 | metadata: 32 | labels: 33 | app: k8s-php-thinkphp-hello 34 | spec: 35 | #做一个emptyDir类型,名为wwwroot的volume 用于多个容器共享同一个挂载 36 | volumes: 37 | - name: wwwroot 38 | emptyDir: {} 39 | # 私有docker 镜像仓库 40 | # imagePullSecrets: 41 | # - name: registrykey-qlcoud-1 42 | # 自定义设置POD的hosts 43 | hostAliases: 44 | - ip: "127.0.0.1" 45 | hostnames: 46 | - "php-fpm" 47 | initContainers: 48 | #php程序本身 49 | - name: appphp 50 | image: "wwek/k8s-php-thinkphp-hello:app-v1" 51 | imagePullPolicy: Always 52 | # 复制php程序文件到wwwroot volume 53 | command: ["sh", "-c", "cp -r /var/www/k8s-php-thinkphp-hello /appdata"] 54 | volumeMounts: 55 | - mountPath: /appdata 56 | name: wwwroot 57 | containers: 58 | #php-fpm php运行环境 59 | - name: php-fpm 60 | image: "wwek/k8s-php-thinkphp-hello:php-fpm-7.2" 61 | imagePullPolicy: Always 62 | volumeMounts: 63 | - mountPath: /var/www 64 | name: wwwroot 65 | #openrsty webserver 66 | - name: openresty 67 | image: "wwek/k8s-php-thinkphp-hello:openresty" 68 | imagePullPolicy: Always 69 | volumeMounts: 70 | - mountPath: /var/www 71 | name: wwwroot 72 | ports: 73 | - name: http 74 | containerPort: 80 75 | protocol: TCP 76 | # livenessProbe: 77 | # httpGet: 78 | # path: / 79 | # port: http 80 | # readinessProbe: 81 | # httpGet: 82 | # path: / 83 | # port: http 84 | resources: 85 | {} 86 | --- 87 | # Ingress 88 | apiVersion: extensions/v1beta1 89 | kind: Ingress 90 | metadata: 91 | name: k8s-php-thinkphp-hello 92 | labels: 93 | app: k8s-php-thinkphp-hello 94 | spec: 95 | rules: 96 | - host: k8sphpthinkphp.com 97 | http: 98 | paths: 99 | - path: / 100 | backend: 101 | serviceName: k8s-php-thinkphp-hello 102 | servicePort: http -------------------------------------------------------------------------------- /openresty/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM wwek/openresty:alpine 2 | 3 | LABEL version="1.0" \ 4 | description="openresty alpine" \ 5 | maintainer="wwek" 6 | 7 | 8 | ARG OPENRESTY_DIR=/usr/local/openresty 9 | ARG OPENRESTY_CONF_DIR=${OPENRESTY_DIR}/nginx/conf 10 | 11 | RUN adduser -D -H -u 1000 -s /bin/bash www-data \ 12 | && mkdir -p ${OPENRESTY_CONF_DIR}/conf.d ${OPENRESTY_CONF_DIR}/vhost 13 | 14 | ADD nginx.conf ${OPENRESTY_CONF_DIR} 15 | COPY sites/ ${OPENRESTY_CONF_DIR}/sites-available 16 | 17 | ARG PHP_UPSTREAM_CONTAINER=php-fpm 18 | ARG PHP_UPSTREAM_PORT=9000 19 | 20 | # Set upstream conf and remove the default conf 21 | RUN echo "upstream php-upstream { server ${PHP_UPSTREAM_CONTAINER}:${PHP_UPSTREAM_PORT}; }" > ${OPENRESTY_CONF_DIR}/conf.d/upstream.conf 22 | 23 | EXPOSE 80 443 24 | 25 | CMD ["/usr/local/openresty/bin/openresty"] 26 | -------------------------------------------------------------------------------- /openresty/README.md: -------------------------------------------------------------------------------- 1 | # openresty 2 | openresty alpine -------------------------------------------------------------------------------- /openresty/nginx.conf: -------------------------------------------------------------------------------- 1 | user www-data; 2 | worker_processes auto; 3 | pid /run/nginx.pid; 4 | daemon off; 5 | 6 | events { 7 | worker_connections 2048; 8 | multi_accept on; 9 | use epoll; 10 | } 11 | 12 | http { 13 | server_tokens off; 14 | sendfile on; 15 | tcp_nopush on; 16 | tcp_nodelay on; 17 | keepalive_timeout 15; 18 | types_hash_max_size 2048; 19 | client_max_body_size 20M; 20 | include mime.types; 21 | default_type application/octet-stream; 22 | access_log /dev/stdout; 23 | error_log /dev/stderr; 24 | gzip on; 25 | gzip_disable "msie6"; 26 | 27 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 28 | ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; 29 | 30 | include conf.d/*.conf; 31 | include sites-available/*.conf; 32 | include vhost/*.conf; 33 | open_file_cache off; # Disabled for issue 619 34 | charset UTF-8; 35 | } 36 | -------------------------------------------------------------------------------- /openresty/sites/app.conf.example: -------------------------------------------------------------------------------- 1 | server { 2 | 3 | listen 80; 4 | listen [::]:80; 5 | 6 | server_name app.test; 7 | root /var/www/app; 8 | index index.php index.html index.htm; 9 | 10 | location / { 11 | try_files $uri $uri/ /index.php$is_args$args; 12 | } 13 | 14 | location ~ \.php$ { 15 | try_files $uri /index.php =404; 16 | fastcgi_pass php-upstream; 17 | fastcgi_index index.php; 18 | fastcgi_buffers 16 16k; 19 | fastcgi_buffer_size 32k; 20 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 21 | #fixes timeouts 22 | fastcgi_read_timeout 600; 23 | include fastcgi_params; 24 | } 25 | 26 | location ~ /\.ht { 27 | deny all; 28 | } 29 | 30 | location /.well-known/acme-challenge/ { 31 | root /var/www/letsencrypt/; 32 | log_not_found off; 33 | } 34 | 35 | #error_log /var/log/nginx/app_error.log; 36 | #access_log /var/log/nginx/app_access.log; 37 | } 38 | -------------------------------------------------------------------------------- /openresty/sites/default.conf.example: -------------------------------------------------------------------------------- 1 | server { 2 | 3 | listen 80 default_server; 4 | listen [::]:80 default_server ipv6only=on; 5 | 6 | server_name localhost; 7 | root /var/www/default; 8 | index index.php index.html index.htm; 9 | 10 | location / { 11 | try_files $uri $uri/ /index.php$is_args$args; 12 | } 13 | 14 | location ~ \.php$ { 15 | try_files $uri /index.php =404; 16 | fastcgi_pass php-upstream; 17 | fastcgi_index index.php; 18 | fastcgi_buffers 16 16k; 19 | fastcgi_buffer_size 32k; 20 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 21 | #fixes timeouts 22 | fastcgi_read_timeout 600; 23 | include fastcgi_params; 24 | } 25 | 26 | location ~ /\.ht { 27 | deny all; 28 | } 29 | 30 | location /.well-known/acme-challenge/ { 31 | root /var/www/letsencrypt/; 32 | log_not_found off; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /openresty/sites/k8s-php-thinkphp-hello.conf: -------------------------------------------------------------------------------- 1 | #log format 2 | log_format access '$remote_addr - $remote_user [$time_local] "$request" ' 3 | '$status $body_bytes_sent "$http_referer" ' 4 | '"$http_user_agent" "$http_x_forwarded_for" ' 5 | '"$http_x_real_ip" "$server_addr" "$host" ' 6 | '"$request_time" "$upstream_response_time" "$upstream_addr" ' 7 | '"$uri" "$time_iso8601"'; 8 | 9 | server { 10 | 11 | # listen 443 ssl http2; 12 | # ssl on; 13 | # ssl_certificate sites-available/ssl/xxx.com.cer; 14 | # ssl_certificate_key sites-available/ssl/xxx.com.key; 15 | # ssl_session_timeout 1d; 16 | # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 17 | # ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; 18 | # ssl_prefer_server_ciphers on; 19 | listen 80 default_server; 20 | listen [::]:80 default_server; 21 | 22 | server_name localhost k8s-php-thinkphp-hello; 23 | root /var/www/k8s-php-thinkphp-hello/public; 24 | index index.php index.html index.htm; 25 | 26 | location / { 27 | try_files $uri $uri/ /index.php?s=$uri&$args; 28 | } 29 | 30 | location ~ \.php$ { 31 | try_files $uri /index.php =404; 32 | fastcgi_pass php-upstream; 33 | fastcgi_index index.php; 34 | fastcgi_buffers 16 16k; 35 | fastcgi_buffer_size 32k; 36 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 37 | include fastcgi_params; 38 | } 39 | 40 | location ~ /\.ht { 41 | deny all; 42 | } 43 | 44 | location /.well-known/acme-challenge/ { 45 | root /var/www/letsencrypt/; 46 | log_not_found off; 47 | } 48 | 49 | access_log /dev/stdout access; 50 | error_log /dev/stderr; 51 | } 52 | -------------------------------------------------------------------------------- /openresty/sites/laravel.conf.example: -------------------------------------------------------------------------------- 1 | server { 2 | 3 | listen 80; 4 | listen [::]:80; 5 | 6 | server_name laravel.test; 7 | root /var/www/laravel/public; 8 | index index.php index.html index.htm; 9 | 10 | location / { 11 | try_files $uri $uri/ /index.php$is_args$args; 12 | } 13 | 14 | location ~ \.php$ { 15 | try_files $uri /index.php =404; 16 | fastcgi_pass php-upstream; 17 | fastcgi_index index.php; 18 | fastcgi_buffers 16 16k; 19 | fastcgi_buffer_size 32k; 20 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 21 | #fixes timeouts 22 | fastcgi_read_timeout 600; 23 | include fastcgi_params; 24 | } 25 | 26 | location ~ /\.ht { 27 | deny all; 28 | } 29 | 30 | location /.well-known/acme-challenge/ { 31 | root /var/www/letsencrypt/; 32 | log_not_found off; 33 | } 34 | 35 | #error_log /var/log/nginx/laravel_error.log; 36 | #access_log /var/log/nginx/laravel_access.log; 37 | } 38 | -------------------------------------------------------------------------------- /php-fpm/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | #-------------------------------------------------------------------------- 3 | # Image Setup 4 | #-------------------------------------------------------------------------- 5 | # 6 | # To edit the 'php-fpm' base Image, visit its repository on Github 7 | # https://github.com/wwek/php-fpm 8 | # 9 | # To change its version, see the available Tags on the Docker Hub: 10 | # https://hub.docker.com/r/wwek/php-fpm/tags/ 11 | # 12 | # Note: Base Image name format {image-tag}-{php-version} 13 | # 14 | 15 | ARG PHP_VERSION=7.2 16 | 17 | FROM wwek/php:${PHP_VERSION}-fpm-alpine 18 | 19 | 20 | # 21 | #-------------------------------------------------------------------------- 22 | # Mandatory Software's Installation 23 | #-------------------------------------------------------------------------- 24 | # 25 | # Mandatory Software's such as ("mcrypt", "pdo_mysql", "libssl-dev", ....) 26 | # are installed on the base image 'wwek/php-fpm' image. If you want 27 | # to add more Software's or remove existing one, you need to edit the 28 | # base image (https://github.com/wwek/php-fpm). 29 | # 30 | 31 | # 32 | #-------------------------------------------------------------------------- 33 | # Optional Software's Installation 34 | #-------------------------------------------------------------------------- 35 | # 36 | # Optional Software's will only be installed if you set them to `true` 37 | # in the `docker-compose.yml` before the build. 38 | # Example: 39 | # - INSTALL_ZIP_ARCHIVE=true 40 | # 41 | 42 | ########################################################################### 43 | # PHP EXTENSION 44 | ########################################################################### 45 | 46 | RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} libzip-dev \ 47 | # Install Php Mysql Client 48 | && docker-php-ext-install mysqli pdo pdo_mysql \ 49 | # Install Php Extension 50 | && printf "\n" | pecl install redis ZendOpcache zip \ 51 | && rm -rf /tmp/pear \ 52 | && docker-php-ext-enable redis opcache zip \ 53 | && apk del pcre-dev ${PHPIZE_DEPS} 54 | 55 | 56 | # Copy opcache configration 57 | COPY ./opcache.ini /usr/local/etc/php/conf.d/opcache.ini 58 | 59 | 60 | ########################################################################### 61 | # Check PHP version: 62 | ########################################################################### 63 | 64 | ARG PHP_VERSION=${PHP_VERSION} 65 | 66 | RUN php -v | head -n 1 | grep -q "PHP ${PHP_VERSION}." 67 | 68 | # 69 | #-------------------------------------------------------------------------- 70 | # Final Touch 71 | #-------------------------------------------------------------------------- 72 | # 73 | 74 | COPY ./phpext.ini /usr/local/etc/php/conf.d 75 | COPY ./xweb.pool.conf /usr/local/etc/php-fpm.d/ 76 | 77 | USER root 78 | 79 | # Clean up 80 | 81 | # 环境变量 82 | ENV MYSQL_HOSTNAME= \ 83 | MYSQL_USERNAME= \ 84 | MYSQL_PASSWORD= 85 | 86 | WORKDIR /var/www 87 | 88 | CMD ["php-fpm"] 89 | 90 | EXPOSE 9000 91 | -------------------------------------------------------------------------------- /php-fpm/mysql.ini: -------------------------------------------------------------------------------- 1 | [MySQL] 2 | ; Allow accessing, from PHP's perspective, local files with LOAD DATA statements 3 | ; http://php.net/mysql.allow_local_infile 4 | mysql.allow_local_infile = On 5 | 6 | ; Allow or prevent persistent links. 7 | ; http://php.net/mysql.allow-persistent 8 | mysql.allow_persistent = On 9 | 10 | ; If mysqlnd is used: Number of cache slots for the internal result set cache 11 | ; http://php.net/mysql.cache_size 12 | mysql.cache_size = 2000 13 | 14 | ; Maximum number of persistent links. -1 means no limit. 15 | ; http://php.net/mysql.max-persistent 16 | mysql.max_persistent = -1 17 | 18 | ; Maximum number of links (persistent + non-persistent). -1 means no limit. 19 | ; http://php.net/mysql.max-links 20 | mysql.max_links = -1 21 | 22 | ; Default port number for mysql_connect(). If unset, mysql_connect() will use 23 | ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the 24 | ; compile-time value defined MYSQL_PORT (in that order). Win32 will only look 25 | ; at MYSQL_PORT. 26 | ; http://php.net/mysql.default-port 27 | mysql.default_port = 28 | 29 | ; Default socket name for local MySQL connects. If empty, uses the built-in 30 | ; MySQL defaults. 31 | ; http://php.net/mysql.default-socket 32 | mysql.default_socket = 33 | 34 | ; Default host for mysql_connect() (doesn't apply in safe mode). 35 | ; http://php.net/mysql.default-host 36 | mysql.default_host = 37 | 38 | ; Default user for mysql_connect() (doesn't apply in safe mode). 39 | ; http://php.net/mysql.default-user 40 | mysql.default_user = 41 | 42 | ; Default password for mysql_connect() (doesn't apply in safe mode). 43 | ; Note that this is generally a *bad* idea to store passwords in this file. 44 | ; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password") 45 | ; and reveal this password! And of course, any users with read access to this 46 | ; file will be able to reveal the password as well. 47 | ; http://php.net/mysql.default-password 48 | mysql.default_password = 49 | 50 | ; Maximum time (in seconds) for connect timeout. -1 means no limit 51 | ; http://php.net/mysql.connect-timeout 52 | mysql.connect_timeout = 60 53 | 54 | ; Trace mode. When trace_mode is active (=On), warnings for table/index scans and 55 | ; SQL-Errors will be displayed. 56 | ; http://php.net/mysql.trace-mode 57 | mysql.trace_mode = Off 58 | 59 | -------------------------------------------------------------------------------- /php-fpm/opcache.ini: -------------------------------------------------------------------------------- 1 | ; NOTE: The actual opcache.so extention is NOT SET HERE but rather (/usr/local/etc/php/conf.d/docker-php-ext-opcache.ini) 2 | 3 | opcache.enable="1" 4 | opcache.memory_consumption="256" 5 | opcache.use_cwd="0" 6 | opcache.max_file_size="0" 7 | opcache.max_accelerated_files = 30000 8 | opcache.validate_timestamps="1" 9 | opcache.revalidate_freq="0" 10 | -------------------------------------------------------------------------------- /php-fpm/phpext.ini: -------------------------------------------------------------------------------- 1 | date.timezone=UTC 2 | display_errors=Off 3 | log_errors=On 4 | 5 | ; Maximum amount of memory a script may consume (128MB) 6 | ; http://php.net/memory-limit 7 | memory_limit = 256M 8 | ; Maximum allowed size for uploaded files. 9 | ; http://php.net/upload-max-filesize 10 | upload_max_filesize = 20M 11 | ; Sets max size of post data allowed. 12 | ; http://php.net/post-max-size 13 | post_max_size = 20M 14 | max_execution_time=600 15 | default_socket_timeout=3600 16 | request_terminate_timeout=600 17 | -------------------------------------------------------------------------------- /php-fpm/xweb.pool.conf: -------------------------------------------------------------------------------- 1 | ; Unix user/group of processes 2 | ; Note: The user is mandatory. If the group is not set, the default user's group 3 | ; will be used. 4 | user = www-data 5 | group = www-data 6 | 7 | ; The address on which to accept FastCGI requests. 8 | ; Valid syntaxes are: 9 | ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on 10 | ; a specific port; 11 | ; 'port' - to listen on a TCP socket to all addresses on a 12 | ; specific port; 13 | ; '/path/to/unix/socket' - to listen on a unix socket. 14 | ; Note: This value is mandatory. 15 | listen = 0.0.0.0:9000 16 | 17 | ; Choose how the process manager will control the number of child processes. 18 | ; Possible Values: 19 | ; static - a fixed number (pm.max_children) of child processes; 20 | ; dynamic - the number of child processes are set dynamically based on the 21 | ; following directives. With this process management, there will be 22 | ; always at least 1 children. 23 | ; pm.max_children - the maximum number of children that can 24 | ; be alive at the same time. 25 | ; pm.start_servers - the number of children created on startup. 26 | ; pm.min_spare_servers - the minimum number of children in 'idle' 27 | ; state (waiting to process). If the number 28 | ; of 'idle' processes is less than this 29 | ; number then some children will be created. 30 | ; pm.max_spare_servers - the maximum number of children in 'idle' 31 | ; state (waiting to process). If the number 32 | ; of 'idle' processes is greater than this 33 | ; number then some children will be killed. 34 | ; ondemand - no children are created at startup. Children will be forked when 35 | ; new requests will connect. The following parameter are used: 36 | ; pm.max_children - the maximum number of children that 37 | ; can be alive at the same time. 38 | ; pm.process_idle_timeout - The number of seconds after which 39 | ; an idle process will be killed. 40 | ; Note: This value is mandatory. 41 | pm = dynamic 42 | 43 | ; The number of child processes to be created when pm is set to 'static' and the 44 | ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. 45 | ; This value sets the limit on the number of simultaneous requests that will be 46 | ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. 47 | ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP 48 | ; CGI. The below defaults are based on a server without much resources. Don't 49 | ; forget to tweak pm.* to fit your needs. 50 | ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' 51 | ; Note: This value is mandatory. 52 | pm.max_children = 100 53 | 54 | ; The number of child processes created on startup. 55 | ; Note: Used only when pm is set to 'dynamic' 56 | ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 57 | pm.start_servers = 20 58 | 59 | ; The desired minimum number of idle server processes. 60 | ; Note: Used only when pm is set to 'dynamic' 61 | ; Note: Mandatory when pm is set to 'dynamic' 62 | pm.min_spare_servers = 20 63 | 64 | ; The desired maximum number of idle server processes. 65 | ; Note: Used only when pm is set to 'dynamic' 66 | ; Note: Mandatory when pm is set to 'dynamic' 67 | pm.max_spare_servers = 100 68 | 69 | ;--------------------- 70 | 71 | ; Make specific Docker environment variables available to PHP 72 | env[DB_1_ENV_MYSQL_DATABASE] = $DB_1_ENV_MYSQL_DATABASE 73 | env[DB_1_ENV_MYSQL_USER] = $DB_1_ENV_MYSQL_USER 74 | env[DB_1_ENV_MYSQL_PASSWORD] = $DB_1_ENV_MYSQL_PASSWORD 75 | 76 | catch_workers_output = yes 77 | --------------------------------------------------------------------------------