Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy php-fpm on docker container and apache/nginx on localhost (Ubuntu)

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

like image 582
Rishi Avatar asked Dec 11 '22 01:12

Rishi


1 Answers

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.

To run Apache on the host, and php-fpm in Docker:

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).

like image 137
jeff-h Avatar answered Dec 12 '22 15:12

jeff-h