If you’re looking for a quick and easy way to set up a PHP development environment with MySQL and phpMyAdmin, DDEV is a great tool. It simplifies local development using Docker, making it perfect for PHP developers. In this tutorial, I’ll show you how to set up everything step by step.
Why Use DDEV?
DDEV makes local development easy by providing a consistent environment using Docker. Here are some benefits:
✅ Quick setup for PHP & MySQL projects
✅ No need to manually install MySQL or Apache
✅ Easy database management with phpMyAdmin
✅ Works on Linux, macOS, and Windows
1. Install DDEV (If You Haven’t Already)
Before we begin, make sure you have:
- Docker installed (Get it here)
- DDEV installed (Installation guide)
You can check if DDEV is installed by running:
ddev version
2. Create a New PHP Project with DDEV
First, create a new project folder and navigate to it:
mkdir my-php-app && cd my-php-app
Now, initialize DDEV for a PHP project:
ddev config --project-type=php --docroot=public --php-version=8.1 --create-docroot
This command:
- Sets up a PHP project
- Defines
public/
as the document root - Uses PHP 8.1 (change this if needed)
Start the environment:
ddev start
At this point, PHP and MySQL are running in your local DDEV environment. 🎉
3. Install phpMyAdmin
DDEV doesn’t include phpMyAdmin by default, but we can add it manually.
Create a custom Docker configuration file:
nano .ddev/docker-compose.override.yml
Paste this inside:
version: '3.6'
services:
phpmyadmin:
container_name: "${DDEV_SITENAME}_phpmyadmin"
image: phpmyadmin:latest
ports:
- "8080:80"
environment:
PMA_HOST: db
PMA_USER: db
PMA_PASSWORD: db
labels:
com.ddev.site-name: "${DDEV_SITENAME}"
Save the file and restart DDEV:
ddev restart
Now, phpMyAdmin is running! 🎉
4. Access phpMyAdmin
Open your browser and go to:
Use these credentials:
- Username:
db
- Password:
db
Now you can manage your MySQL database with a GUI. 🚀
Test Database Connection in PHP
Let’s create a simple PHP script to check if the database is working.
Create an index.php
file:
nano public/index.php
Paste this code inside:
<?php
$host = "db";
$user = "db";
$password = "db";
$database = "db";
$conn = new mysqli($host, $user, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully to the database!";
?>
Save the file.
Now, open:
👉 http://my-php-app.ddev.site
You should see:
Connected successfully to the database!
Final Thoughts
With just a few commands, you now have a fully functional PHP + MySQL + phpMyAdmin development environment using DDEV. This setup makes local development easier, and you don’t have to manually install and configure MySQL or Apache.