<legend id='CziqS'><style id='CziqS'><dir id='CziqS'><q id='CziqS'></q></dir></style></legend>
      <tfoot id='CziqS'></tfoot>
    1. <small id='CziqS'></small><noframes id='CziqS'>

        <bdo id='CziqS'></bdo><ul id='CziqS'></ul>
    2. <i id='CziqS'><tr id='CziqS'><dt id='CziqS'><q id='CziqS'><span id='CziqS'><b id='CziqS'><form id='CziqS'><ins id='CziqS'></ins><ul id='CziqS'></ul><sub id='CziqS'></sub></form><legend id='CziqS'></legend><bdo id='CziqS'><pre id='CziqS'><center id='CziqS'></center></pre></bdo></b><th id='CziqS'></th></span></q></dt></tr></i><div id='CziqS'><tfoot id='CziqS'></tfoot><dl id='CziqS'><fieldset id='CziqS'></fieldset></dl></div>
      1. Docker-Compose 不会卷我的 php.ini 文件

        时间:2024-05-11
          <i id='X6gjS'><tr id='X6gjS'><dt id='X6gjS'><q id='X6gjS'><span id='X6gjS'><b id='X6gjS'><form id='X6gjS'><ins id='X6gjS'></ins><ul id='X6gjS'></ul><sub id='X6gjS'></sub></form><legend id='X6gjS'></legend><bdo id='X6gjS'><pre id='X6gjS'><center id='X6gjS'></center></pre></bdo></b><th id='X6gjS'></th></span></q></dt></tr></i><div id='X6gjS'><tfoot id='X6gjS'></tfoot><dl id='X6gjS'><fieldset id='X6gjS'></fieldset></dl></div>

            • <bdo id='X6gjS'></bdo><ul id='X6gjS'></ul>
            • <small id='X6gjS'></small><noframes id='X6gjS'>

              <tfoot id='X6gjS'></tfoot>
                <tbody id='X6gjS'></tbody>

              • <legend id='X6gjS'><style id='X6gjS'><dir id='X6gjS'><q id='X6gjS'></q></dir></style></legend>
                  本文介绍了Docker-Compose 不会卷我的 php.ini 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 docker-compose 对我的 php.ini 文件进行卷,这样我就可以在本地计算机上即时进行更改,以查看它如何影响主机.不幸的是,到目前为止,我能够将 php.ini 文件放入容器的唯一方法是直接在 Dockerfile 中创建.

                  附件是容器运行良好的图像,当前设置如下.

                  我的 Dockerfile 如下:

                  来自 ubuntu:14.04维护者 Joe Astrahan <jastrahan@poolservice.software>卷 ["/var/www"]运行 apt-get 更新 &&apt-get install -y software-properties-common &&apt-get 更新 &&apt-get 安装 -y 阿帕奇2卷曲libcurl3libcurl3-开发php5php5-cli libapache2-mod-php5php5-gdphp5-json php5-ldap php5-mysqlnd php5-pgsql php5-卷曲mysql客户端复制配置/php.ini/etc/php5/apache2/php.ini# 安装 php-5.5.30复制配置/install_php-5.5.30.sh/tmp/install_php-5.5.30.sh运行/bin/bash/tmp/install_php-5.5.30.sh复制配置/apache_default.conf/etc/apache2/sites-available/000-default.conf复制配置/运行/usr/local/bin/run运行 chmod +x/usr/local/bin/run运行 a2enmod 重写#这将允许我们修改容器中的文件以进行测试,如果我们需要运行 apt-get 更新 &&apt-get install -y vim曝光 80CMD ["/usr/local/bin/run"]

                  我的 docker-compose.yml 文件如下:

                  版本:'2'服务:数据库直播:图片:mysql:5.5.52卷:- ./db_data_live:/var/lib/mysql重启:总是环境:MYSQL_ROOT_PASSWORD:****MYSQL_数据库:****MYSQL_用户:****MYSQL_密码:****数据库开发:图片:mysql:5.5.52卷:- ./db_data_dev:/var/lib/mysql重启:总是环境:MYSQL_ROOT_PASSWORD:****MYSQL_数据库:****MYSQL_用户:****MYSQL_密码:****phpmyadmin:依赖于取决于:- 数据库直播- 数据库开发图片:phpmyadmin/phpmyadmin环境:PMA_ARBITRARY:1重启:总是端口:- 8081:80"网络:建造: ./依赖于取决于:- 数据库直播- 数据库开发卷:- ./web:/var/www- ./config/php.ini:/etc/php5/apache2/conf.d/custom.ini- ./logs/apache_error.log:/var/log/apache2/error.log- ./logs/apache_access.log:/var/log/apache2/access.log- ./config/apache_default.conf:/etc/apache2/sites-enabled/000-default.conf重启:总是端口:- 80:80"- 443:443"

                  我尝试按照此处的建议,

                  使用的额外文件

                  运行

                  #!/bin/bash设置-ePHP_ERROR_REPORTING=${PHP_ERROR_REPORTING:-"E_ALL & ~E_DEPRECATED & ~E_NOTICE"}sed -ri 's/^display_errorss*=s*Off/display_errors = On/g'/etc/php5/apache2/php.inised -ri 's/^display_errorss*=s*Off/display_errors = On/g'/etc/php5/cli/php.inised -ri "s/^error_reportings*=.*$//g"/etc/php5/apache2/php.inised -ri "s/^error_reportings*=.*$//g"/etc/php5/cli/php.iniecho "error_reporting = $PHP_ERROR_REPORTING" >>/etc/php5/apache2/php.iniecho "error_reporting = $PHP_ERROR_REPORTING" >>/etc/php5/cli/php.ini源/etc/apache2/envvars &&执行/usr/sbin/apache2 -DFOREGROUND

                  install_php-5.5.30.sh

                  #!/bin/bash# 安装依赖apt-get -y 更新 &&apt-get 安装 -y 构建必不可少的apache2-开发者libxml2-dev# 下载 PHP 5.5.30 源代码光盘/tmpcurl -fsSL http://php.net/get/php-5.5.30.tar.bz2/from/this/mirror |焦油 xjf -cd php-5.5.30# 配置构建选项./configure --prefix=/usr--with-config-file-path=/etc/php5/apache2 --with-config-file-scan-dir=/etc/php5/apache2/conf.d --禁用-pdo --禁用-json --启用mbstring --with-apxs2# 编译并安装NUM_CORES=`cat/proc/cpuinfo |grep 处理器 |厕所-l`使 -j $NUM_CORES进行安装# 配置扩展目录echo 'extension_dir="/usr/lib/php5/20121212"' >>/etc/php5/apache2/php.ini# 清理rm -rf/tmp/php-5.5.30/tmp/install_php-5.5.30.sh

                  我的文件结构

                  解决方案

                  我找到了答案,在config目录下放了一个名为custom.php.ini的文件(如果你按照我的目录结构的话).

                  在我的示例中设置这样的卷...

                  卷:- ./web:/var/www- ./config/custom.php.ini:/etc/php5/apache2/conf.d/custom.php.ini

                  默认情况下,额外 php 文件的扫描目录将在 conf.d 目录中查找.这些文件将覆盖主 php.ini 的设置.我用 asp_tag 选项将其关闭和打开对此进行了测试.只要您执行以下操作,它就可以正常工作.

                  完成这项工作的技巧是使用 docker-compose down 而不是 docker-compose kill

                  这会删除容器及其缓存文件.PHP 只在启动时加载配置文件一次,其他文件因此更改 php.ini 或自定义文件后需要此 docker-compose down 来强制更改.

                  I'm trying to use docker-compose to volume my php.ini file so I can make changes on the fly on my local machine to see how it affects the host machine. Unfortunately the only way I've been able to get the php.ini file into the container is directly during creation in the Dockerfile so far.

                  Attached is an image of the container running fine with the current settings below.

                  My Dockerfile is below:

                  FROM ubuntu:14.04
                  MAINTAINER Joe Astrahan <jastrahan@poolservice.software>
                  
                  VOLUME ["/var/www"]
                  
                  
                  RUN apt-get update && 
                      apt-get install -y software-properties-common && 
                      apt-get update && 
                      apt-get install -y 
                        apache2 
                        curl 
                        libcurl3 
                        libcurl3-dev 
                        php5 
                        php5-cli 
                        libapache2-mod-php5 
                        php5-gd 
                        php5-json 
                        php5-ldap 
                        php5-mysqlnd 
                        php5-pgsql 
                        php5-curl 
                        mysql-client
                  
                  COPY config/php.ini /etc/php5/apache2/php.ini
                  
                  # install php-5.5.30
                  COPY config/install_php-5.5.30.sh /tmp/install_php-5.5.30.sh
                  RUN /bin/bash /tmp/install_php-5.5.30.sh
                  
                  
                  COPY config/apache_default.conf /etc/apache2/sites-available/000-default.conf
                  COPY config/run /usr/local/bin/run
                  
                  RUN chmod +x /usr/local/bin/run
                  RUN a2enmod rewrite
                  
                  #This will allow us to modify files in the container for testing if we need to
                  RUN apt-get update && 
                      apt-get install -y vim
                  
                  EXPOSE 80
                  CMD ["/usr/local/bin/run"]
                  

                  My docker-compose.yml file is below:

                  version: '2'
                  services:
                      dblive:
                          image: mysql:5.5.52
                          volumes:
                              - ./db_data_live:/var/lib/mysql
                          restart: always
                          environment:
                              MYSQL_ROOT_PASSWORD: ****
                              MYSQL_DATABASE: ****
                              MYSQL_USER: ****
                              MYSQL_PASSWORD: ****
                  
                      dbdev:
                          image: mysql:5.5.52
                          volumes:
                              - ./db_data_dev:/var/lib/mysql
                          restart: always
                          environment:
                              MYSQL_ROOT_PASSWORD:****
                              MYSQL_DATABASE: ****
                              MYSQL_USER: ****
                              MYSQL_PASSWORD: ****
                  
                      phpmyadmin:
                          depends_on:
                              - dblive
                              - dbdev
                          image: phpmyadmin/phpmyadmin
                          environment:
                              PMA_ARBITRARY : 1
                          restart: always
                          ports:
                              - "8081:80"
                  
                      web:
                          build: ./
                          depends_on:
                              - dblive
                              - dbdev
                          volumes:
                              - ./web:/var/www
                              - ./config/php.ini:/etc/php5/apache2/conf.d/custom.ini
                              - ./logs/apache_error.log:/var/log/apache2/error.log
                              - ./logs/apache_access.log:/var/log/apache2/access.log
                              - ./config/apache_default.conf:/etc/apache2/sites-enabled/000-default.conf
                          restart: always
                          ports: 
                              - "80:80"
                              - "443:443"
                  

                  I tried following the advice here, can't upate php.ini file in Docker container, by creating a custom.ini file and mounting it in that location. I actually did it correctly I think because if you look at my image I attached for phpinfo(), you can see that under additional .ini files parsed my custom.ini is there at the end. I did a test though by setting asp_tags = On instead of Off and I can't. phpinfo() will always show it as off. Refer to my attached image of it showing it off despite loading my config file.

                  I'm not even sure if its really honoring any of the commands in there at all?

                  Extra Files Used

                  Run

                  #!/bin/bash
                  set -e
                  
                  PHP_ERROR_REPORTING=${PHP_ERROR_REPORTING:-"E_ALL & ~E_DEPRECATED & ~E_NOTICE"}
                  sed -ri 's/^display_errorss*=s*Off/display_errors = On/g' /etc/php5/apache2/php.ini
                  sed -ri 's/^display_errorss*=s*Off/display_errors = On/g' /etc/php5/cli/php.ini
                  sed -ri "s/^error_reportings*=.*$//g" /etc/php5/apache2/php.ini
                  sed -ri "s/^error_reportings*=.*$//g" /etc/php5/cli/php.ini
                  echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/apache2/php.ini
                  echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/cli/php.ini
                  
                  source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND
                  

                  install_php-5.5.30.sh

                  #!/bin/bash
                  
                  # install dependencies
                  apt-get -y update && 
                  apt-get install -y 
                    build-essential 
                    apache2-dev 
                    libxml2-dev
                  
                  # download PHP 5.5.30 source code
                  cd /tmp
                  curl -fsSL http://php.net/get/php-5.5.30.tar.bz2/from/this/mirror | tar xjf -
                  cd php-5.5.30
                  
                  # configure build options
                  ./configure --prefix=/usr 
                              --with-config-file-path=/etc/php5/apache2 
                              --with-config-file-scan-dir=/etc/php5/apache2/conf.d 
                              --disable-pdo 
                              --disable-json 
                              --enable-mbstring 
                              --with-apxs2
                  
                  # compile and install
                  NUM_CORES=`cat /proc/cpuinfo | grep processor | wc -l`
                  make -j $NUM_CORES
                  make install
                  
                  # configure extension directory
                  echo 'extension_dir="/usr/lib/php5/20121212"' >> /etc/php5/apache2/php.ini
                  
                  # cleanup
                  rm -rf /tmp/php-5.5.30 /tmp/install_php-5.5.30.sh
                  

                  My file structure

                  解决方案

                  I found the answer, put a file called custom.php.ini in the config directory (if you are following my directory structure).

                  Set the volumes like this in my example...

                  volumes:
                              - ./web:/var/www
                              - ./config/custom.php.ini:/etc/php5/apache2/conf.d/custom.php.ini
                  

                  By default the scan directory for extra php files will look in the conf.d directory. These files will overwrite the settings of the main php.ini. I tested this with the asp_tag option turning it Off and On. It works fine as long as you do the following below.

                  The trick to making this work is to use docker-compose down instead of docker-compose kill

                  This removes the containers and their cache files. PHP only loads the configuration file once at bootup and the other files so changing the php.ini or the custom file after requires this docker-compose down to force the change.

                  这篇关于Docker-Compose 不会卷我的 php.ini 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Docker 的 PHP7 Alpine 映像上安装 php memcached 扩展? 下一篇:使用官方 Alpine Docker 映像将 yaml 扩展添加到 php

                  相关文章

                    <tfoot id='XPwA9'></tfoot>

                    1. <small id='XPwA9'></small><noframes id='XPwA9'>

                        <bdo id='XPwA9'></bdo><ul id='XPwA9'></ul>
                    2. <legend id='XPwA9'><style id='XPwA9'><dir id='XPwA9'><q id='XPwA9'></q></dir></style></legend>
                    3. <i id='XPwA9'><tr id='XPwA9'><dt id='XPwA9'><q id='XPwA9'><span id='XPwA9'><b id='XPwA9'><form id='XPwA9'><ins id='XPwA9'></ins><ul id='XPwA9'></ul><sub id='XPwA9'></sub></form><legend id='XPwA9'></legend><bdo id='XPwA9'><pre id='XPwA9'><center id='XPwA9'></center></pre></bdo></b><th id='XPwA9'></th></span></q></dt></tr></i><div id='XPwA9'><tfoot id='XPwA9'></tfoot><dl id='XPwA9'><fieldset id='XPwA9'></fieldset></dl></div>