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
Environment variables ignored by php-fpm #74
Environment variables ignored by php-fpm #74
Comments
For reference, this discussion may also have some useful tips: https://groups.google.com/forum/#!topic/docker-user/FCzUbjTIp_0 |
Here's a workaround that does the job for me. It would be great if we could include that in the php-fpm image:
run-php-fpm:
|
If you're going to re-expose the whole environment, |
Not sure what you mean. Where would you put that and what does it do? I've added the whole environment as this is the same what the mod_php module does in Apache. It's what you'd probably expect from inside PHP. |
Ahhh, now i see: http://php.net/manual/en/install.fpm.configuration.php. Why didn't I find this earlier? Spent quite some time to find a solution (and there are obviously others who also missed this). So shouldn't this be set by default in this image? I think, env vars is the way to go with docker images. |
From http://php.net/manual/en/install.fpm.configuration.php:
You'd put it in your FWIW, I don't think the |
Or maybe it should be the default... I'm not sure actually. |
Hmm, why not? I don't think it's a security issue as mod_php does the same in Apache. Wouldn't you agree, that PHP apps should follow the 12factor principles and use env vars? If that's the case, we will always need this. |
I'd just say that the fact that |
BTW, if you're going to have a script like |
Ok, thanks. But undoing the above in my project now anyway :) |
|
@mathroc Can you explain why you're against |
oops that was a mistake :/ I meant |
I think in general it's a good idea to have |
@sherter Then why is this different to the default configuration PHP apache module? The same would apply there. I can't see why it would make more sense in php-fpm. And as said before: Environment variables are a very common way to configure your docker container at runtime. So they should work by default, for both, Apache module and php-fpm. |
This is the same default that is in debian when installing the $ cat /etc/php5/fpm/pool.d/www.conf
...
; Clear environment in FPM workers
; Prevents arbitrary environment variables from reaching FPM worker processes
; by clearing the environment in workers before env vars specified in this
; pool configuration are added.
; Setting to "no" will make all environment variables available to PHP code
; via getenv(), $_ENV and $_SERVER.
; Default Value: yes
;clear_env = no That said, since php is the only process in the container, I think it would be sane to change from upstream's default and add |
Allows php scripts executed with FPM to access env vars such as env vars from linked containers see docker-library#74
Cool, thanks! |
Fixed in #93 |
|
Hi! just googled this issue and it looks like a good place for my 5 cents.it's not according this concrete docker image, but a caution to a docker image writers: many docker images are built so that all passwords are configured during the first So personally I decided that it should be always separated. I build my own containers with all sensitive data being provided during the build step. Then I run it without providing any passwords. Yes, not very share-friendly and not that much convenient, but it works. Please let me know if I'm missing something, or if you feel like I'm doing this completely wrong. Thanks! |
Hi @olegstepura giving your credentials to external services is a recommended practice (eg: http://12factor.net/config). I'm wondering, how are your storing your passwords in the container in a way that someone "who can eval some code on the server" cannot access your passwords ? |
@olegstepura That's not what this issue is about. Environment variables are usually passed at runtime to a container, not when you build them. |
@mathroc Well, if it's a password for connecting to this container - it won't be saved in plaintext (password for connecting to Mysql - may be). For example I setup a hybrid container (I know it's not the Docker way, I would never do this, but let's assume) with PHP and openssh server. For SFTP access I need to setup a unix user. I need to provide this password either during
@mikehaertl Sorry, if this was completely wrong place to write this. Didn't find better one to connect to experts. This issue seem very close to the issue I try to discuss. And yes, concrete issue has nothing to do with my discussion. |
|
sed -i "s|;*clear_env\s*=\s*yes|clear_env = no|g" /etc/php5/php-fpm.conf |
Thank you very mach |
This is strange - I've uncommented |
For those of us on CentOS 7 who can't use |
Answer was discussed here docker-library/php#74 not and expert though
As a necessary step, enable all environment variables to be seen in PHP. See docker-library/php#74
Answer was discussed here docker-library/php#74 not and expert though
In the case you were starting
|
@kamihouse when you run |
yes me too |
For those who still don't have access to from
|
If you use the php-fpm variant, environment variables (e.g. for linked docker hosts) are not available in your
$_ENV
var in your PHP scripts. This is a problem as usually docker containers are configured via environment variables (following the 12 factor principles). While this is rather a PHP problem, I still think that the official php-fpm image should provide a workaround for this, as otherwhise it's pretty much useless.For php-fpm all environment variables have to be listed in the
php-fpm.conf
like:So I suggest to create a wrapper script to first add all variables from
env
to the configuration, before actually starting php.The text was updated successfully, but these errors were encountered: