Skip to main content
CakeDC Blog

A quick CakePHP Local environment with DDEV

In the realm of web development, a seamless local environment is the bedrock for efficient and stress-free coding. Enter DDEV, a powerful tool that simplifies the setup process and empowers developers to dive into their projects with ease.

In this blog post, we'll embark on a journey to demystify the process of setting up a local development environment using DDEV. Whether you're a seasoned developer or just starting in the world of web development, optimizing your local environment can significantly enhance your workflow.

Pre Conditions :

Install Docker https://docs.docker.com/get-docker/ and install DDEV https://ddev.readthedocs.io/en/stable/

Step 1: Create a new CakePHP project skeleton 

composer create-project cakephp/app myproject

A new folder "myproject" will be created with a CakePHP project skeleton inside. Go to this new directory and proceed with the following instructions.

Step 2: Initial ddev setup

Run ddev config
This will do the initial ddev setup, press enter for all questions. 

Run ddev auth ssh
This will add ssh key authentication to the ddev-ssh-auth container

Step 3: Adjust the settings

Inside "myproject" a new .ddev folder will be created, open config.yaml  and adjust there: php version, database and the database url environment. 

For PHP:
php_version: "8.1"

For the database:

database:
  type: mysql
  version: "8.0"

For the environment variable:

web_environment:
    - DATABASE_URL=mysql://db:db@db/db

Step 4: Start ddev

ddev start 

This will spin up the project.

Step 5: Open your application

ddev launch

This will open your project in a browser.

 

Once you have the application up and running, some useful commands you could run are:

  • ddev composer to execure composer
  • ddev mysql to get into the database
  • ddev ssh takes you into the web container.

In this link https://ddev.readthedocs.io/en/latest/users/usage/cli/ you can see more useful commands.

 

Hope you enjoy playing with DDEV!

 

 

 

 

 

Back to all articles
We Bake with CakePHP