PHP Development Environment using Docker

cudacoder

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:

  1. 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?

  2. 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!

tux

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.

edited at
0

Comments

0 comments
Login to comment

Related

Vagrant or Docker for environment development

Docker permissions development environment using a host mounted volume

How setup a Node.js development environment using Docker Compose

Rich editors in a Docker development environment

Docker for local development with multiple environment

Using Docker in local development

Setting up a PHP environment using Atom ( for HTML+CSS+JS+PHP development)

VirtualBox or Docker for shared software development environment?

How to set up Docker development environment on Debian?

PySpark Development Environment in an Ubuntu 16.04 Docker Container

Docker: Best practice for development and production environment

Using Symfony in Docker Environment for Production

Using docker during the development workflow

Development environment for Linux wireless using sparse

Using hoogle in a haskell development environment on nix

Rails and WebSockets using SSL/TLS in development environment

Using geocoder only in development or production environment

Setting up Java + svn + Eclipse+ Tomcat , development environment with docker

Run docker as non-root in a development environment for an specific process

How to set up a environment for python application development in Docker Desktop

Docker - Environment variables not overwriting php.ini

Pass Environment Variable to Apache PHP Docker Container

PHP Local development - minikube or docker-compose?

docker-compose.yml environment variable to php environment variable

Setting up your dev environment using docker

Docker Compose - Command using Container Environment Variable

Docker share environment variables using volumes

Using environment variable for volume name in docker compose

Docker compose volume definition using environment variable