- Docker installed on your local machine
- Composer installed globally or locally
- Freshly installed Cakephp 4.5 Using Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Initiate and run your local copy of Cakephp4
composer create-project --prefer-dist cakephp/app:~4.0 myapp
This project is a CakePHP 4.5 application running on PHP 8.2, Apache/2.4.57, and MariaDB 11.1.2. This README will guide you through the installation process.
While inside your fresh Cakephp4
- Clone the Repository:
https://github.com/cs-michaelc/cakephp4-mariadb-php-docker
Then move files to root your Cakephp4 root folder
mv cakephp4-mariadb-php-docker/* ~/myapp/
- Modify MariaDB Configuration:
Open the docker-compose.yml file and locate the db service. Modify the MYSQL_ROOT_PASSWORD and MYSQL_DATABASE values to your preferred values.
For example:
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: myapp
- Change the base Setting in config/app.php:
Open the config/app.php file in your CakePHP application. Update the 'base' value from / to false:
'App' => [
'namespace' => 'App',
'encoding' => env('APP_ENCODING', 'UTF-8'),
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'),
'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'),
'base' => false,
],
- Change the Datasource host in config/app_local.php:
Open the config/app.php file in your CakePHP application. Update the 'host' value from localhost to myapp_db_1:
Note: myapp_db_1 is the name of the mariadb container once you build the dockerfile and docker-compose file.
'Datasources' => [
'default' => [
'host' => 'myapp_db_1',
'username' => 'root',
'password' => 'root',
'database' => 'myapp',
- Build and Start Docker Containers:
Run the following commands to build and start the Docker containers:
docker-compose build
docker-compose up -d
- Access the Application:
Open your web browser and access the application at http://localhost.
Run dockers ps -a to check if the containers are running
docker ps -a
You may need to access the container for various tasks. Here's how to do it:
- To go inside the webapp container, run the following command:
docker exec -it myapp_web_1 bash
Once inside the container, you can run commands specific to the web application.
To install additional packages, for example run the following commands inside the container:
composer require "cakephp/authentication:^2.4"
composer require "cakephp/authorization:^2.0"
- To set up your database or perform database-related tasks, access the MariaDB container:
docker exec -it myapp_db_1 bash
Log in to the MariaDB server by running:
mariadb -u root -p
- Note that changes made to your codebase will be automatically synced with the Docker container instance.