Helm + Kubernetes, load and enable extensions or modules in PHP

六月ゝ 毕业季﹏ 提交于 2021-02-19 05:59:05

问题


i've problem when i run a php deployment with kubernetes becouse don't load the modules or extensions libraries.

My deployment file is this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: php
  labels:
    app: php
spec:
  selector:
    matchLabels:
      app: php
  replicas: 1
  template:
    metadata:
      labels:
        app: php
    spec:
      containers:
      - name: php
        image: php:7-fpm
        env:
          - name: PHP_INI_SCAN_DIR
            value: :/usr/local/etc/php/conf.custom
        ports:
        - containerPort: 9000
        lifecycle:
          postStart:
            exec:
              command: ["/bin/sh","-c","docker-php-ext-install pdo pdo_mysql mysqli && docker-php-ext-enable pdo pdo_mysql mysqli"]
        volumeMounts:
          - name: php-conf
            mountPath: /usr/local/etc/php/conf.custom
      volumes:
        - name: php-conf
          configMap:
            name: php

And my ConfigMap is this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: php
  labels:
    app: php
data:
  wordpress-custom.ini: |-
    upload_max_filesize = 100M
    post_max_size = 100M
  default.ini: |-
    extension=pdo_mysql.so
    extension=mysqli.so

Later i go into the Pod with command "exec -it" and i put again "docker-php-ext-enable mysqli" to check it, but i receive the message "warning: mysqli (mysqli.so) is already loaded!", but when i run the "phpinfo()" command, i see "upload_max_filesize = 100M" and "post_max_size = 100M" updated, but i can't see modules enabled.

What i can do? very thank's


回答1:


The problem is that your docker CMD is to run php-fpm

https://github.com/docker-library/php/blob/bb16de8a711d1ba1dc76adf4665b3b1c06a06922/7.3/stretch/fpm/Dockerfile#L266

and after container started you cannot change loaded to memory php configuration.

You need to restart php-fpm to apply changes, but restart kills container and you loose all changes. To add some libraries for php you should to create your own docker image and install all your libraries into the image instead of installing it in runtime.

Check also this issue on github https://github.com/docker-library/php/issues/331

So answer is to create your own image and install all required extensions with docker RUN command

FROM php:7-fpm

RUN apt-get install php-pdo php-mysql 

After that you have to build this image

docker build -t php:7-fpm-mysql .

push it to some docker registry. For example hub.docker.com

docker push php:7-fpm-mysql

NOTE: php mysql extension is deprecated since PHP 5.5.*, use PDO instead



来源:https://stackoverflow.com/questions/55117000/helm-kubernetes-load-and-enable-extensions-or-modules-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!