We can deploy apache and php in separate docker containers and then link them.
But is there any way to install apache locally (using apt-get install apache2) and php-fpm in docker container and then link them?
Thanks
Yes. Since you are using php-fpm with Apache as you should (instead of mod_php), you will have something similar to this in your Docker-based Apache site configurations:
<FilesMatch \.php$>
SetHandler "proxy:fcgi://php-fpm-container:9000"
</FilesMatch>
The above works when both php-fpm and apache are running in separate docker containers; php-fpm-container
refers to the php-fpm container.
So long as your Docker php-fpm container exposes port 9000 to the host, Apache won't know or care whether that is served from the host or from inside docker.
Your apache site configs will need to be modified to point at localhost:
<FilesMatch \.php$>
SetHandler "proxy:fcgi://localhost:9000"
</FilesMatch>
Incidentally this is a pretty neat way to run multiple different PHP versions on one host and one Apache server. Just expose each php-fpm container on a different port (perhaps 9001, 9002 etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With