thecodingmachine / docker-images-php

A set of PHP Docker images
MIT License
791 stars 140 forks source link

How to use the FPM image for serving #195

Open MrMage opened 4 years ago

MrMage commented 4 years ago

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

mbrodala commented 4 years ago

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 ```yaml 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 ```apache 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 SetHandler "proxy:fcgi://app:9000" ```
moufmouf commented 4 years ago

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

mbrodala commented 4 years ago

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.

laukstein commented 4 years ago

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.

MrMage commented 4 years ago

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?

beejaz commented 2 years ago

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/