-
Notifications
You must be signed in to change notification settings - Fork 2k
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
PHP-FPM + nginx version #54
Comments
We can't really do an FPM with Nginx image since it would be two separate processes in the image, which would require something like supervisord and that is not the direction we currently want for official images. We are working on documentation to run Nginx and FPM together. |
I understand what you mean and support that view also, but having two containers just for a simple web-application looks also a bit too much to me - anyway - looking forward to the docs and your solution. |
I also had this thought today, and I'm looking forward to the docs! |
I've just wanted to share my take on it https://github.com/wtool/nginx (control of PHP version trought env variable) and https://github.com/wtool/php (builds all php versions{latest 5.3+} with php-build). |
Here's my approach https://github.com/phundament/docker - tailored for our app and with composer pre-installed, but you'll get the idea. |
I also tried to use the fpm only version (php:5.6.5-fpm, docker 4.1) but can't get the fpm process to successfully bind to 9000. The fpm process outputs "ready for incoming connections" and thats it. Further investigations with netstat show now LISTEN statement at all. So I guess, the php-fpm manager doesn't start properly. As we currently deploy out php apps with chef scripted nginx + php-fpm I don't want to include apache as a new depency. So I am very interested in having a solid solution for php-fpm and I want to avoid maintaining out own php-fpm Dockerfiles. I appreciate any help. |
Where did you run netstat? How is the nginx container finding out how to |
O.k. I have to confess. There were no problem in the fpm server. fpm binds sucessfully to 9000, I have used the wrong commands. Nevertheless, I will also have to include an nginx for myself, because for deploying wordpress we also need to serve some static content, which we can't deliver with the php-fpm server, as I understand for now. So I don't see a solution to not violate the docker best practive of having only one running process in a container at the time. Maybe we can mount the wordpress sources in both containers, but that would require running them on the same host. Or stick to the provided mode-php-apache concept. But this will introduce another dependency, and we haven't used apache for a long time. Any suggestions? |
@bennibu I had the same thoughts. Could somebody elaborate more on the difference between the php-fpm "service" for nginx and the apapche mod_php - I know that the module is in a child fork of apache and therefore not counted as a separate service. What unexpected things could happen when using only one container with a running nginx and a PHP in the same container? It looks to me like, if we'd use the PHP cli (theoretically speaking) with nginx we'd not violate the container principle. But that setup makes no sense. |
As one example, the nginx process could die, and you wouldn't notice right |
@bennibu I'd look at making an analogous image to @tianon Do you think it would be reasonable to have a |
@md5 that sounds divine :) |
I have a quick POC for the Wordpress part here: https://github.com/md5/wordpress/commit/c299bbb20d8021ec144a72fdcc79d8b959aa447a I tried to whip up a quick nginx config to work with it and got it to proxy to the FPM container, but I hit a redirect loop on the install and don't have time today to work on it anymore. The only thing I had to do besides copying the I also switched the I'm not ready to open a PR for that |
Ooh, using "tar" as an "rsync" replacement is clever. This definitely needs some love (as you outlined), but it looks like some |
Might be useful to warn people that .htaccess only applies to Apache and running WordPress on NGINX may need extra configuration. IIRC, some plugins (and WordPress itself) modify the .htaccess to add rewrite-rules etc. and I'm not sure those properly detect NGINX. Sure, this is something the user should research, but there's a lot of non-too experienced users using WordPress that may need the extra pointers. Looks like this page collects issues/hints for running WordPress on NGINX; http://codex.wordpress.org/Nginx |
Since Nginx would be running in a different container and the nginx/php-fpm On Fri, Jan 30, 2015 at 3:03 PM, Sebastiaan van Stijn <
|
Yes, the image should be accompanied with some example(s) and Nice work on the image, though, having an official WordPress NGINX |
I just had some time to play around and get a working Nginx config to front the I started from the config in the Codex, but it seemed be having issues due to not passing through |
@md5 Thanks for your work so far. I like this approach and I will give it a try later. Although we haven't used wordpress with apache in our deployments a long time ago, I will give this combination another chance. Especially when the wordpress world still sticks to apache-php as default deployment stack. Beside this I also think, that with an nginx in front of apache-php we maybe can profit of both worlds. Simplicity in setup and deployment and fast delivery of static contents via nginx (or varnish as the better proxy cache). I am not sure yet, we have to evaluate both strategies. Beside the decision about the webserver the biggest problem is still wordpress requirements for a writable filesystem for uploads/themes so you can't scale your deployments over multiple hosts without a distributed filesystem. I opened an issue in the wordpress docker repo. |
I've built a working php-fpm + nginx setup now for my yii2-dockerized project. It was actually pretty simple. I build a small nginx image with a dedicated configuration for a yii2 application. And fire up the two (or 3 with db) machines with a simple app:
build: ./
expose:
- "9000"
nginx:
build: ./nginx
ports:
- "8080:80"
links:
- app
volumes_from:
- app So I don't think there's a much better way to use php-fpm. If we don't want to break the one-process-per-container principle, this is the way to go. EDIT: Oh, and of course it's crucial, that the file paths to the app code on both machines are exactly the same. So I've created a volume for this in the |
See also my approach which contains nothing else as needed: https://github.com/stucki/docker-lemp |
So IMO what is really the issue, is only the lack of documentation. A fpm+nginx image is not really in the spirit of docker as was mentioned before. Maybe the README could contain a note on the Something along the lines of: To bring up an application with
In the
Example:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
root /var/www/html;
index index.html index.php;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_pass php-fpm:9000;
try_files $uri =404;
}
}
} docker build -t mynginx .
docker run -d -v /path/to/app:/var/www/html --name php-fpm php:5.6.6-fpm
docker run -p 8080:80 --volumes-from php-fpm --link php-fpm:php-fpm mynginx |
@mikehaertl agreed 👍 I did a very similar config to yours as a gist a while back for the I'm sure nobody would object to having this better documented, it's just a matter of someone having the time and inclination to do so. |
@md5 Oh, indeed. Must have missed that :). |
@mikehaertl Thanks for the above commands. I tried your example and it worked flawlessly Thanks alot |
Thanks for this interesting discussion. To me, as well, it makes totally sense to run run FPM and nginx in two separate containers. But: How does this scale? E.g. in AWS Elastic Beanstalk with a load balancer in front of it? If you use php-apache, you’ve got one image per app and AWS may spawn/kill as many containers as needed. In the FPM scenario this doesn’t work anymore. You would need two containers (nginx+fpm) per instance … UPDATE: Ah, well. This is how Amazon proposes doing it, two containers per instance: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_ecstutorial.html |
@intellent I got confused by your comment because "EBS" usually means Elastic Block Store. At first I thought you actually meant ECS (i.e. EC2 Container Service), but I see now that you're actually talking about Elastic Beanstalk (which uses ECS under the hood for container deployments). Looks like the docs you found are the right ones for what you're trying to do. 👍 |
@md5 Oh, one should never make acronyms up on the fly. Sorry for the confusion. Updated. :-) |
@intellent From our tests I can say that the nginx container usually needs much less resources than the fpm container. Which means that you can, i.e. insert a haproxy container in between nginx and fpm and just scale the fpm process. |
@schmunk42 Very interesting. How do you manage the deployment? Self-managed infrastructure? It should also be possible to use nginx as load balancer for the fpm instances, right? |
Yes, nginx should also be able to do that. |
@schmunk42 How can I get a 1:30 relationship between nginx and php-fpm? The only solution I can think of is to have haproxy load balancing multiple nginx/php-fpm container pairs. Could you share how you balance multiple php-fpm backends with a single nginx frontend? |
@jamiehannaford To be honest, I haven't fully tested it, but the idea would be something like this: http://nginx.org/en/docs/http/ngx_http_upstream_module.html
The tricky part is scaling up and down and changing the config dynamically, that's a feature |
Would be great to have this documented! |
Hi @mikehaertl , Im using what you have suggested, all are running fine but in web browser im not getting any response. in nginx logs response code is 200 but no matter in the web browser. |
I solved it by using xdrum/nginx-extras image for perl/lua support in nginx config |
This really should be handled by using two containers linked together somehow (either with linking, Docker Networks, or some other method). To that end, I'm closing this issue in favor of docker-library/docs#238. 👍 |
Since there's an Apache flavour available of the PHP Docker image, what's about a similar solution for PHP -FPM + nginx?
PS: I found no instructions for
fpm
at all - I can start the image, but I didn't manage it to get anything out of port 9000, not even an error.The text was updated successfully, but these errors were encountered: