my production server is running Docker with a classic structure Db-Container, Server-Container and Php-Fpm container.
What i would like to do is to split the source
Use docker-compose expose and FastCgiExternalServer in conf file or vhosts file
(Note this is an approach I will be taking and am still researching. I will update as I know more. But it should hopefully give you an outline of what to do too. I do update my answers, not an empty promise, see this example here: Getting a LAMP stack running on a Vagrant VM (under windows 7 host), full instructions?)
Install docker-compose which provides an official standardised way to batch/automate running of your docker containers, using a docker-compose.yml
file, rather than using the command line docker
command to start up each command individually.
In the docker-compose.yml
file, define your php-fpm service, e.g.:
services:
use the EXPOSE
keyword statement/instruction to make available the port of your php-fpm to apache.
An example of expose
is shown in this article: Multiple versions of AMP in One Host where in the example docker-compose.yml
contains this expose statement:
expose:
- "3306"
- which enables the sql database to be available to other docker containers.
You will also need to ensure that the php files are available to both php and apache containers - CREDIT: https://stackoverflow.com/a/40449377/227926
Then, that same expose:
port, together with the service name will need to be referenced from the Apache FastCgiExternalServer
directive in the vhosts file or conf file. Choosing a vhosts file or conf file to put the directive in is, I think, what seems to be a personal preference though research may reveal differences where one or the other suits your circumstance more.
An example in the conf file would look something like:
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
What conf file should I put this in?
Answer: there are several options (as indicated above), in a little more detail these are (assuming Ubunut/Debian Linux is the OS that Apache is running on top of): - httpd.conf - 000-default.conf (the default vhost) (in sites-available) - yoursite.conf (in sites-available) - and (e.g.) /etc/apache2/conf-available/php5.6-fpm.conf
Where would these conf files be located?
Answer: inside your apache docker container. You will need to use the docker-compose.yml file to add (inject) the setup described into the container, once you have defined the services. You can execute, from the docket-compose.yml the standard linux commands to insert text into config files.
You should automate the adding of these settings rather than go in an manually edit Apache config files inside the container, because: 1) automate means that the setup is repeatable and can therefore be used for different platforms in the development workflow: dev, qa, uat, live/prod 2) no manual work required 3) Docker containers are intended to be ephemeral in that they can be destroyed and recreated. Any persistent data should be kept outside of them - in the host -(config in Dockerfiles, docker-composer files, assets (images) in separate folders, database store outside of the container and on the host too.
Examples of FastCgiExternalServer directive:
References to Debian/Ubuntu conventions for conf files and Apache
Discussions about PHP-FPM - https://serverfault.com/questions/645755/differences-and-dis-advanages-between-fast-cgi-cgi-mod-php-suphp-php-fpm
Useful related information about docker-file.yml statements
Similar discussions on running seperate containers together