This example shows basic PHP web application:
- It uses composer for dependency management
- Static files are served from
public/
directory. They are included in NginX container - All requests are redirected to
index.php
file - There are two containers:
hello-world
(which runs php-fpm) andhello-world-nginx
(which runs NginX)
You need following software installed to run this example:
- docker
- docker-compose
- make
You don't need to install PHP, apache, WAMP, LAMP, etc. - it's all handled by docker
.
Please see docker-compose.yml
for the example.
To start local containers with mounted volume, use the following commands:
make build
make up
Then open the website at: http://localhost/
All changes to files are quickly available on the website - just refresh it. Opcache timestamp validation is enabled and it's checked every 2 seconds.
Xdebug is not enabled. Please check xdebug example for more information about this topic.
Please see docker-compose.prod.yml
for the example.
If you execute make build
, it builds two containers: one with PHP and another with NginX and static files.
Those two containers are ready for automated CI tests and production run. They don't depend on mapping local files, as code and assets are built in. They also don't require bind-mounting of static files from PHP to NginX containers (which is available with docker
, but not supported by platforms like AWS ECS or Kubernetes).
There is a health-check endpoint, which can be used as readiness and liveness probe (for kubernetes) or as a target health check for loadbalancers: /healthz
. It returns HTTP 200
response, with body: OK
Opcache configuration is by default active and set to never validate timestamps (as files never change in live containers).
NginX container waits for PHP container to become available before it starts (and responds OK
on health check endpoint). This helps with plaforms like Kubernetes, where we make sure that new release becomes available only after all containers are ready.