12 factor php service skeleton
TL;DR
install
macOs: brew install docker
, (*1)
Linux/Unix:, (*2)
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
apt-add-repository 'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
apt-get update
apt-get install docker-engine
use
make
to build, (*3)
make dev
to build and run local version, (*4)
Dev version will appear here: http://localhost:8081, (*5)
What's inside
- nginx
- php7.1 + php-fpm
- slim ^3.0
- supervisord to rule them all
12 factor Manifest
Codebase
Create project, (*6)
composer create-project fridaylabs/service -s dev --no-install --ignore-platform-reqs <SERVICE_NAME>
and push it to your repo, (*7)
Dependencies
Solved by composer, (*8)
Config
- All configs should be pulled from environment.
- Don't use variables like APPLICATION_ENVIRONMENT!
- Use
.env
file for local setup
Backing services
Use config for connecting with DB, Queue or other services, (*9)
Build, release, run
- Type
make
to build
- Type
make dev
to build and run local version
-
TODO: Push your branch to run tests, merge branch to release
Processes
- Make sure, that your app is stateless.
- Store all your data into remote services
Port binding
- App exposing 80 and 443 port.
- Default dev port is 8081
Concurrency
Solved by php-fpm, (*10)
Disposability
Solved by supervisord, (*11)
Dev/prod parity
Solved by docker and composer, (*12)
Logs
- Nginx, php-fpm and app writes logs to stdout
- Don't write logs to FS
Admin processes
TODO, (*13)