简体   繁体   English

如何设置 max_execution_time php-fpm docker 镜像?

[英]how to set max_execution_time php-fpm docker image?

I am using docker image for php5.6-fpm from https://hub.docker.com/_/php/ .我正在使用来自https://hub.docker.com/_/php/ 的php5.6-fpm docker 图像。

When I check php.ini location in phpinfo() it says it is /usr/local/etc/php, but when I look into that path there is no php.ini located there.当我检查 phpinfo() 中的 php.ini 位置时,它说它是 /usr/local/etc/php,但是当我查看该路径时,那里没有 php.ini。

Now I want to change max_execution_time php variable.现在我想更改 max_execution_time php 变量。 How can I do that in custom docker image?如何在自定义 docker 映像中执行此操作?

What you do is, you derive from the official FPM image and then use RUN+sed to change the value, eg:你要做的是,你从官方的 FPM 镜像中派生出来,然后使用 RUN+sed 来改变值,例如:

FROM php:7.1

RUN sed -e 's/max_execution_time = 30/max_execution_time = 100/' -i /etc/php/7.1/fpm/php.ini

Please ensure the path /etc/php/7.1/fpm/php.ini is correct in your case, it depends on the image used, i did not verify above the php:7.1 one.请确保路径/etc/php/7.1/fpm/php.ini在您的情况下是正确的,这取决于所使用的图像,我没有在 php:7.1 上面验证。

Hint: When you need to change a lot of values, you might rather want to simply use your own php.ini in your image提示:当您需要更改很多值时,您可能更愿意在图像中简单地使用自己的 php.ini

COPY php.ini /etc/php/7.1/fpm/php.ini

But thats just in case, changing just a few values can be done with sed但这只是为了以防万一,可以使用 sed 完成更改几个值

add following line to Dockerfile将以下行添加到 Dockerfile

RUN echo 'max_execution_time = 120' >> /usr/local/etc/php/conf.d/docker-php-maxexectime.ini;

then然后

docker-compose build 
docker-compose up

or或者

docker build 
docker start your_machine_name

provided PHP_INI_SCAN_DIR = /usr/local/etc/php/conf.d.提供 PHP_INI_SCAN_DIR = /usr/local/etc/php/conf.d。 You can check it in running您可以在运行中检查它

<? phpinfo();

should say应该说

Scan this dir for additional .ini files | /usr/local/etc/php/conf.d

Easy solution:简单的解决方案:

  1. Navigate your docker image and find the configuration that mostly adapts to your needs between php.ini-development and php.ini-production (the first on may be more indicated for logging, second for production-like env.).导航您的 docker 映像并在php.ini-developmentphp.ini-production之间找到最适合您需求的配置(第一个可能更适合用于日志记录,第二个用于类似生产的环境)。

  2. Copy the configuration file in your project folder, or where you keep the Dockerfile or docker-compose.yml将配置文件复制到您的项目文件夹中,或者您保存Dockerfiledocker-compose.yml

I'm using the php:7.4.12-apache image as starting point, the php.ini file must be copied into /usr/local/etc/php/ , and it will be loaded automatically on next start.我使用php:7.4.12-apache图像作为起点,必须将 php.ini 文件复制到/usr/local/etc/php/ ,它会在下次启动时自动加载。

  1. Now edit any property you need into the configuration file, and save it as php.ini现在将您需要的任何属性编辑到配置文件中,并将其保存为php.ini

  2. Finally, the file must be copied into the image / container, see how in the following lines.最后,必须将文件复制到图像/容器中,请参阅以下几行。

Dockerfile (to copy into image) Dockerfile(复制到镜像中)

Add COPY ./php.ini /usr/local/etc/php/php.ini添加COPY ./php.ini /usr/local/etc/php/php.ini

OR或者

docker-compose.yml (to copy into container) docker-compose.yml(复制到容器中)

services:
    php-apache-dev:

        ...

        volumes:
            - ./php.ini:/usr/local/etc/php/php.ini

        ...

this configuration has the php.ini in same folder as docker-compose.yml此配置在与 docker-compose.yml 相同的文件夹中具有 php.ini

Note: honestly I prefer to copy into container, because I can edit the configuration and simply re-launch the container, without rebuilding the image, but it's up to you.注意:老实说,我更喜欢复制到容器中,因为我可以编辑配置并简单地重新启动容器,而无需重建映像,但这取决于您。

I find this solution more useful in development, it's simpler, and you can edit many properties, not just only one.我发现这个解决方案在开发中更有用,它更简单,您可以编辑许多属性,而不仅仅是一个。

Happy coding!快乐编码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM