简体   繁体   中英

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/ .

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.

Now I want to change max_execution_time php variable. How can I do that in custom docker image?

What you do is, you derive from the official FPM image and then use RUN+sed to change the value, eg:

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.

Hint: When you need to change a lot of values, you might rather want to simply use your own php.ini in your image

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

add following line to 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. 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.).

  2. Copy the configuration file in your project folder, or where you keep the Dockerfile or docker-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.

  1. Now edit any property you need into the configuration file, and save it as php.ini

  2. Finally, the file must be copied into the image / container, see how in the following lines.

Dockerfile (to copy into image)

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

OR

docker-compose.yml (to copy into container)

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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