Docker container for CakePHP.
Based on the official Docker image, php:<version>-apache.
Quick start of development - CakePHP is a great framework, but to start using it, you need to set up php, some extensions, a web server such as apache or nginx and more. This container comes with all that already in place and acts as a kitchen to bake a cake.
FROM sukun1899/cakephp:4-php8
COPY . /var/www/cake_app
WORKDIR /var/www/cake_app
Then, run the commands to build and run the Docker image:
$ docker build -t my-cake-app .
$ docker run -p 8080:80 -it --rm --name my-running-cake-app my-cake-app
You can run your cakePHP application using the Docker image directly:
$ docker run -p 8080:80 --rm --name my-running-cake-app -v "$(pwd)":/var/www/cake_app sukun1899/cakephp:4-php8
Usually you will use a database, so docker-compose may be useful.
The following is example.
version: "3.9"
services:
web:
container_name: my-cake-app
image: sukun1899/cakephp:4-php8
ports:
- "8080:80"
volumes:
- .:/var/www/cake_app
db:
container_name: my-cake-db
image: "mysql:8"
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: my_app
MYSQL_USER: my_app
MYSQL_PASSWORD: secret
The first thing to do is create your project directory.
$ mkdir my-cake-app
$ cd my-cake-app/
Run create-project command via the Docker.
$ docker run -it --rm --name my-new-app -v "$PWD":/var/www/cake_app sukun1899/cakephp:4-php8 composer create-project --no-interaction --working-dir=/var/www/cake_app --prefer-dist cakephp/app:4.* .
You can also use xdebug, which is very useful debugging tool.
Prepare a configuration file.
$ cat conf.d/docker-php-ext-xdebug.ini
zend_extension=xdebug
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.start_with_request=yes
Create a Dockerfile, and install xdebug.
FROM sukun1899/cakephp:4-php8
# setup xdebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
COPY ./conf.d /usr/local/etc/php/conf.d
If you set up like .github/workflows/ci.yml
, it's available in GitHub Actions.
The following is example.
name: CakePHP App CI
on:
push:
branches:
- master
pull_request:
branches:
- '*'
jobs:
testsuite:
runs-on: ubuntu-latest
container:
image: sukun1899/cakephp:4-php8
env:
WORKSPACE: /var/www/cake_app
services:
db:
image: mysql:8
ports:
- "3306:3306"
options: --health-cmd "mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: test_my_app
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Move to workspace
run: |
mv ${GITHUB_WORKSPACE}/* ${WORKSPACE}
- name: composer install
run: |
composer install --prefer-dist -d ${WORKSPACE}
- name: Run PHPUnit
run: |
cd ${WORKSPACE}
vendor/bin/phpunit