docker-images-php icon indicating copy to clipboard operation
docker-images-php copied to clipboard

How to use the FPM image for serving

Open MrMage opened this issue 5 years ago • 6 comments

It appears that the FPM images use php-fpm as their entry point, indicating that they only launch the FPM service but do not support serving HTTP requests directly.

Is that assumption correct, or does the image somehow launch Apache as well?

In the former case, do you have any recommendations on how to connect this with an Apache or Nginx instance that functions as an HTTP server? Ideally, that server should serve both the FPM service via HTTP as well as some additional static assets. I might be able to wire something up myself but was wondering whether you had already considered that use case — an FPM service by itself still needs an HTTP server, after all.

(I have searched for existing issues about this, but could not find any.)

MrMage avatar Mar 06 '20 12:03 MrMage

We are using a setup where we use both the fpm and the slim-apache image. For the latter we disable the PHP7 module which is loaded by default and use an Apache proxy handler to integrate PHP-FPM

docker-compose.yml
version: '3'

services:
  app:
    image: thecodingmachine/php:7.4-v3-fpm-node8
    volumes:
      - ./:/var/www/html

  apache:
    image: thecodingmachine/php:7.4-v3-slim-apache
    environment:
      APACHE_EXTENSION_PHP7: 0
      APACHE_EXTENSIONS: proxy proxy_fcgi
    volumes:
      - ./:/var/www/html
      - ./.docker/apache/vhost.conf:/etc/apache2/sites-available/000-default.conf:ro
.docker/apache/vhost.conf
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/${APACHE_DOCUMENT_ROOT}

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLProxyEngine on

    <FilesMatch \.php$>
        SetHandler "proxy:fcgi://app:9000"
    </FilesMatch>
</VirtualHost>

mbrodala avatar Mar 06 '20 15:03 mbrodala

@mbrodala Thanks for sharing your setup! It is interesting to see how you disable the PHP7 to get a "pure" apache server :)

@MrMage, your assumption is right, the FPM image does not come with Apache installed.

moufmouf avatar Mar 09 '20 11:03 moufmouf

Just for clarity: we don't simply use a basic/custom image for Apache to benefit from the same way configuration and permissions are handled.

mbrodala avatar Mar 09 '20 11:03 mbrodala

I would like better if could have a single image for it like thecodingmachine/php:slim-apache containing the latest version of php and apache.

laukstein avatar Apr 10 '20 11:04 laukstein

Sorry to „revive“ this thread, but what is your approach to serving both static assets and the app when using PHP-FPM and Nginx/Apache in separate containers? Do you simply copy the entire „app“ directory (containing both code and assets) to both the „fpm“ and the „apache“ image?

MrMage avatar May 16 '20 15:05 MrMage

Sorry to „revive“ this thread, but what is your approach to serving both static assets and the app when using PHP-FPM and Nginx/Apache in separate containers? Do you simply copy the entire „app“ directory (containing both code and assets) to both the „fpm“ and the „apache“ image?

Nginx need to have the static files, not the code. So I use it like this in a multi stage Dockerfile (simplified below):

FROM thecodingmachine/php:8.1-v4-slim-fpm as php

COPY project ./
...
RUN php bin/console cache:clear
RUN php bin/console assets:install

FROM nginx:1.21-alpine AS nginx

COPY --from=php /var/www/html/public public/

beejaz avatar Sep 08 '22 17:09 beejaz