This Docker image allows for serving php-fpm apps with nginx. It uses Alpine Linux, so it's lean and mean. Designed to be easily used within Docker Swarm.
This image is designed for use within a Compose file. To use it, you should:
- Create a service in your docker-compose.yml file using this image (joshwalsh/nginx-for-php-fpm)
- Create a service in your docker-compose.yml file which runs your PHP application with PHP-FPM
- The PHP-FPM image can contain the application code anywhere in its filesystem (
/var/www/html
is commonly used) - The php-fpm.conf file should contain a
chdir
directive which points to the directory that you want served by nginx (e.g. for a Laravel app, you might wish to serve/var/www/html/public/
) - The PHP-FPM service should either be named
php-fpm
, or should be aliased asphp-fpm
on a network that the nginx service has access to - The PHP-FPM service should listen on port 9000
- The PHP-FPM image can contain the application code anywhere in its filesystem (
- Create a named volume to store the content that you want nginx to serve
- Add this volume to the php-fpm service so it maps to the location from step 2b
- Add this volume to the nginx service so it maps to
/var/www/html
- Make it so that the nginx service
depends_on
the php-fpm service - If you want to apply any customisations to the nginx configuration, (e.g. redirect or rewrite rules) you can use a config with the target path set to /etc/nginx/conf.d/custom.conf or you can share it from your php-fpm image via a named volume