6

I have a PHP application running on docker and based on php:7.3-alpine3.9

For a big form, I am posting more than 1000 inputs, and I not only I get the error

Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0`

but worst, only 1000 input are passed to the backend

So it looks like I'd need to change the max_input_vars in the php.ini, but how can I do that ?

Ing. Luca Stucchi
  • 3,070
  • 6
  • 36
  • 58

2 Answers2

9

Usually, there is some kind of configuration directory that is scanned for further files. Try to place a file containing your local settings there, like the following:

php.ini.local:

max_input_vars = 20000

in your Dockerfile:

FROM php:7.3-alpine3.9

# Project-specific ini settings
COPY ./php-ini-overrides.ini /etc/php7/conf.d/

Another way could be to mount that single file through a Docker volume (this keeps the container configuration cleaner and is more simple if you don't want to use a Dockerfile for other purposes; additionally, you don't need to update the container when changing the configuration, but only restart it):

volumes:
  - ./php-ini-overrides.ini:/etc/php7/conf.d/php-ini-overrides.ini

This will work the best way, as you don't have to modify any existing file or keep track of changes from the upstream container

As a short hint: if the solution does not work directly, check whether you need to adjust the folder to put that file into. Another base image might place that folder to another location

Nico Haase
  • 11,420
  • 35
  • 43
  • 69
  • 1
    Hi Nico, thanks, but I am fine with the file provided by Alpine. I don't want to be forced to change it manually: I am using a PHP image because I want PHP working off the shelf, and keeping track of the changes of `php.ini` it's something that I just don't want to do – Ing. Luca Stucchi Aug 08 '19 at 14:46
  • I don't get that: if you don't want to change the image, don't do it, use it as it is. Doing magic work with the default file from that image sounds less good to me than using the suggested way to change configuration settings through an additional file – Nico Haase Aug 09 '19 at 07:12
  • And, additionally, this should also work through a custom volume which I've added to the answer – Nico Haase Aug 09 '19 at 07:13
  • 1
    Hi Nico, I tried to make your solution work, since I agree that a single override row in an incremental file works better than modifying the original `php.ini`. And after some attempts I made it work: the trick was using the directory `/etc/php7/conf.d/` instead of the one that you suggested. And it worked perfectly. I am going to remove my answer since yours is way better ! Would you be so kind and change the reference to the directory, since in Alpine it does not work with the `/usr/local/etc/php/conf.d/` ? – Ing. Luca Stucchi Aug 09 '19 at 16:01
  • Why would you call it php.ini.local and then call php-ini-overrides.ini, a compoletely different name? – Philip Jun 27 '22 at 03:39
0

Adding sed to your Dockerfile, as you mentioned in your answer, is one way of doing it but, I'd say that's not the best way to do it. What I'd suggest is that you keep the properly functioning php.ini along with your source code and mount it to your container at the time you spin it using docker-compose.yml file.

version: "3.7"

services:
  app:
    image: app_image
    volumes:
      - ./php.ini:/etc/php7/php.ini

This makes debugging much easier and is quite clean.

7_R3X
  • 3,904
  • 4
  • 25
  • 43
  • Thanks, but I am not using docker-composer, I am deploying on Amazon ECS. Moreover, I don't want to extract the `php.ini` from alpine image and manage his evolution during the time: I was hoping to leave that to the alpine community – Ing. Luca Stucchi Aug 08 '19 at 14:48
  • @LucaStucchi: Alpine and PHP community provide their software with some default values. If you change those defaults, it becomes your responsibility to manage them as part of your code. It's called "configuration as code". – 7_R3X Aug 09 '19 at 06:59
  • In the solution provided by Nico Haase there is no need to manage the whole `php.ini`, and it works perfectly. Thanks the same for your solution, but I still think that if I can't manage configuration files provided by Alpine, I should not. Thanks the same for your help – Ing. Luca Stucchi Aug 09 '19 at 16:10