I'm currently trying to setup a PHP development environment using NGINX and PHP-FPM Docker containers.
Now I know that this can be accomplished either as a single container running both services, or even as a multiple container setup where each service runs in its own container (that's based on my research so far).
My problem can be divided into two questions:
How would one setup multiple different PHP apps and have them communicate with one another, using the multiple container solution? Will I have to setup a NGINX container for every PHP-FPM one, or can I setup one NGINX container and use it with multiple different PHP-FPM ones?
Is the multiple container solution even a good one for a development environment? Or am I approaching this totally wrong?
Thanks in advance, any tips would be appreciated!
Since, you are asking about multi container environment, I believe you are using Docker compose for your application. To answer your question more elaborately.
1) Lets say we have three containers in docker compose, one for nginx, an fpm container for laravel and another fpm container for magento. then you docker compose file would look like. The below snippet is only an example
nginx:
image: nginx:latest
ports:
- "80:80"
- "443:443"
links:
- "fpmlaravel"
- "fpmmagento"
fpmlaravel:
image: php:latest
volumes:
- ./data/laravel/:/var/www/laravel
links:
- "nginx"
fpmmagento:
image: php:latest
volumes:
- ./data/magentoroot/:/var/www/magento
links:
- "nginx"
The nginx vhost file for magento would be
# PHP back end
upstream backend {
server fpmmagento:9000;
}
server {
listen 80;
server_name www.magento.dev magento.dev;
root /var/www/magento;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass backend;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param MAGE_RUN_TYPE $mage_type;
fastcgi_param MAGE_RUN_CODE $mage_code;
}
}
For fpm, make sure that fpm image is listening on port 9000.
2) Yes it is possible to have one nginx container, which routes between different fpm backends, based on nginx vhosts. But, in general it is considered a bad practice, as the main idea behind docker is to segregate your applications.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments