Home

Awesome

🍰 CakePHP Docker

Build CakePHP Docker Kubernetes PHP NGINX MySQL

A cakephp/app template for Docker Compose and Kubernetes. You might also be interested in CakePHP Galley which is similar to Laravel Sail or DevilBox.

Dependencies:

ServiceHost:PortDocker HostImage
PHP8.3-FPM w/ Xdebug 3-phpcnizzardini/php-fpm-alpine:8.3-latest
NGINX 1.19localhost:8080webnginx:1.19-alpine
MySQL 8localhost:3607dblibrary/mysql:8

Installation

Fork and clone this repository then run:

make init

That's it! Now just remove app/* from .gitignore. You may also want to remove .assets and adjust defaults in .github, .docker, and .kube.

Note: make init and make init.nocache output interactively, while make start and make up do not.

Mac Notes

  1. Change your SHELL in the Makefile to /bin/zsh. This improves various output from the Makefile such as emoji's.

  2. Mac ships with an older version of sed so install gnu-sed for some targets in the Makefile:

brew install gnu-sed

Then update sed to gsed in the Makefile.

Usage

After install browse to http://localhost:8080 to see the CakePHP welcome page.

A Makefile is provided with some optional commands for your convenience. Please review the Makefile as these commands are not exact aliases of docker-compose commands.

Make CommandDescription
makeShows all make target commands
make initRuns docker build, docker-compose up, and copies over env files
make init.nocacheSame as make.init but builds with --no-cache
make startStarts services docker-compose -f .docker/docker-compose.yml start
make stopStops services docker-compose -f .docker/docker-compose.yml stop
make upCreate and start containers docker-compose -f .docker/docker-compose.yml up -d
make downTake down and remove all containers docker-compose -f .docker/docker-compose.yml down
make restartRestarts services docker-compose -f .docker/docker-compose.yml restart
make php.shPHP terminal docker exec -it --user cakephp <PHP_CONTAINER> sh
make php.restartRestarts the PHP container
make db.shDB terminal docker exec -it <DB_CONTAINER> sh
make db.mysqlMySQL terminal mysql -u root -h 0.0.0.0 -p --port 3307
make web.shWeb terminal docker exec -it <WEB_CONTAINER> sh
make xdebug.onRestarts PHP container with xdebug.mode set to debug,coverage
make xdebug.offRestarts PHP container with xdebug.mode set to off
make composer.installdocker exec <PHP_CONTAINER> composer install --no-interaction
make composer.testdocker exec <PHP_CONTAINER> composer test
make composer.checkdocker exec <PHP_CONTAINER> composer check

PHP

See .docker/README.md for details.

Shell:

make php.sh

Helper commands:

make composer.install
make composer.test
make composer.check

MySQL

See .docker/README.md for details.

Shell:

make db.sh

MySQL shell (requires mysql client on your localhost):

make db.mysql

NGINX

See .docker/README.md for details.

Shell:

make web.sh

Xdebug

Xdebug is disabled by default. To toggle:

make xdebug.on
make xdebug.off

PHPStorm + Xdebug

Xdebug 3's default port is 9003.

Go to File > Settings > Languages & Frameworks > PHP > Servers

Map your project's app directory to the absolute path on the docker container /srv/app

Reinstall

To completely reinstall delete existing containers and images, then remove the app/ directory and run make init again.