Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change common php settings via environment variable #765

Closed
J0WI opened this issue Dec 12, 2018 · 6 comments
Closed

Change common php settings via environment variable #765

J0WI opened this issue Dec 12, 2018 · 6 comments
Labels
Request Request for image modification or feature

Comments

@J0WI
Copy link
Contributor

J0WI commented Dec 12, 2018

There was a request to change memory_limit via environment variable:
nextcloud/docker#568

There are other settings that are frequently requested to change, like the upload limit.
Is it worth to allow some common settings to be set via environment variables?

https://secure.php.net/manual/en/configuration.file.php#example-36

@rcdailey
Copy link

You could go for the kitchen-sink solution and just map all environment variables with a specific prefix to their corresponding php.ini settings, such as a prefix like PHP_INI_. So if I specified PHP_INI_MEMORY_LIMIT=2G, you'd have some generic code that removed the prefix, did lower case conversion of what's left, and inserted it into a php.ini, so you'd end up with memory_limit=2G.

Something like that would be pretty sophisticated I think, and given my merge request for specifically just memory limit, it would be really nice to get that in first (since it's a quick stopgap at the very least) and then replace it later with a more flushed-out and generic system (assuming that's the direction you're trying to go)

@wglambert wglambert added the Request Request for image modification or feature label Dec 12, 2018
@J0WI
Copy link
Contributor Author

J0WI commented Dec 14, 2018

@yosifkit would you accept a PR implementing this?

@TimWolla
Copy link
Contributor

see also: TimWolla/docker-adminer#36

@tianon
Copy link
Member

tianon commented Dec 24, 2018

This is definitely not something I'm very keen on seeing explicitly implemented here in the php image itself -- we've already got a fair amount of "Docker-specific" behavior, and I really don't feel like it's a good idea for us to add even more (especially behavior which amounts to simply appending environment variable values directly to a .ini file verbatim, which seems pretty trivial to implement via a short script which could even be pretty easily embedded directly in the command: supplied to a PHP-based image, if needed).

@tianon
Copy link
Member

tianon commented Dec 31, 2018

Here's an example simple command/script which can be used to accomplish this pretty trivially (explicitly ignoring PHP_INI_DIR which is set in the base):

$ docker run ... -e PHP_INI_MEMORY_LIMIT=2G php:7.3-apache bash -exc 'for env in "${!PHP_INI_@}"; do [ "$env" != 'PHP_INI_DIR' ] || continue; val="${!env}"; var="${env#PHP_INI_}"; var="${var,,}"; echo "$var = $val"; done > "$PHP_INI_DIR/docker-env.ini"; exec apache2-foreground'

Note this won't work very well for directives which contain . (which isn't POSIX-compliant in environment variable names, so will sometimes not work appropriately).

Alternatively (and more supportably long-term IMO), take advantage of php.ini explicitly supporting environment variables (https://secure.php.net/manual/en/configuration.file.php#example-36) with something simpler (and much more explicit) like this:

FROM php:7.3-apache

ENV PHP_INI_MEMORY_LIMIT 128M
RUN echo 'memory_limit = ${PHP_INI_MEMORY_LIMIT}' > "$PHP_INI_DIR/docker-env.ini"

@Thijs-Riezebeek
Copy link

Thijs-Riezebeek commented Mar 6, 2019

For future reference, man php has the following to say:

-d foo[=bar]   Define INI entry foo with value bar

So you could also use the -d option to increase INI settings, such as the memory limit:

php -d memory_limit=128M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Request Request for image modification or feature
Projects
None yet
Development

No branches or pull requests

6 participants