mattrayner / docker-lamp

A simple LAMP image using Ubuntu, Apache, PHP and MySql in a single image
Apache License 2.0
588 stars 261 forks source link

How to change post_max_filesize & cie? #144

Closed tbarbette closed 6 days ago

tbarbette commented 1 week ago

Hi all!

I'd like to automatize the famous change to increase post_max_size &cie. I tried this Dockerfile but even if the cat confirms the change is written, the value is ignored and attaching to the container I see the change is not persisted, it's back to 10M.

Any idea?

FROM mattrayner/lamp:latest-1804

# Your custom commands
RUN sed -i 's/upload_max_filesize \= [0-9]\+M/upload_max_filesize \= 1024M/g' /etc/php/*/apache2/php.ini
RUN sed -i 's/post_max_size \= [0-9]\+M/post_max_size \= 1024M/g' /etc/php/*/apache2/php.ini
RUN cat /etc/php/8.0/apache2/php.ini | grep post_max_size

CMD ["/run.sh"]
pzhlkj6612 commented 1 week ago

Hi!

the value is ignored and attaching to the container I see the change is not persisted

How did you check it in your container? Please paste your command and result in text.

tbarbette commented 1 week ago

Thanks for the help !

docker exec -it suspicious_meitner cat /etc/php/8.0/apache2/php.ini | grep post_max_size                                                    <
post_max_size = 10M

suspicious_meitner being the name of the container running aside.

pzhlkj6612 commented 1 week ago

I think you've missed two env vars PHP_UPLOAD_MAX_FILESIZE and PHP_POST_MAX_SIZE:

https://github.com/mattrayner/docker-lamp/blob/24c620372a4e89afc109126485b7ced5245a77eb/1804/Dockerfile#L81-L83

These two env vars will overwrite the value in the INI file:

https://github.com/mattrayner/docker-lamp/blob/24c620372a4e89afc109126485b7ced5245a77eb/supporting_files/run.sh#L19-L29

Hence, to change the config, your Dockerfile should look like this:

FROM mattrayner/lamp:latest-1804

# Your custom commands
ENV PHP_UPLOAD_MAX_FILESIZE=1024M
ENV PHP_POST_MAX_SIZE=1024M

CMD ["/run.sh"]

See also: LegacyKeyValueFormat | Docker Docs

tbarbette commented 6 days ago

Ah yes indeed ! Did not see the env in the doc :) Sorry !