Blog
Using PhpStorm Docker Integration to Run Laravel Apps Consistently
Learn how to configure PhpStorm’s Docker integration to run, debug, and test a Laravel app inside identical containers, eliminating environment drift.
Published by Tasadduq Burney
21 Oct 2025, 12:22 UTC
3 min92.2K views0

Problem: Environment drift causes hard‑to‑reproduce bugs
When developers run PHP locally, differences in PHP version, installed extensions, or configuration files can make a feature work on one machine but fail on another. This "works on my machine" syndrome wastes time during debugging and testing.
Thesis: PhpStorm’s Docker integration gives every team member an identical runtime
By defining the application stack in Docker Compose and telling PhpStorm to use the container as a remote PHP interpreter, the IDE can edit, run, and debug code inside the same environment that will be used in production.
Worked example: Laravel project with app, database, and cache services
- Create a Docker Compose file in the project root (e.g.,
docker-compose.yml):version: '3.8' services: app: image: php:8.2-apache container_name: laravel_app working_dir: /var/www/html volumes: - ./:/var/www/html ports: - "8000:80" depends_on: - db - redis db: image: mysql:8.0 container_name: laravel_db environment: MYSQL_ROOT_PASSWORD: example MYSQL_DATABASE: laravel MYSQL_USER: laravel MYSQL_PASSWORD: secret ports: - "3306:3306" redis: image: redis:7-alpine container_name: laravel_redis ports: - "6379:6379" - Start the stack from a terminal (you need Docker Desktop or Engine running and user must be in the
dockergroup or run with sudo):cd /path/to/laravel-project docker compose up -d - Register the Compose file in PhpStorm
- Open
Tools → Docker → Configurationand ensure the Docker daemon URL points to your Docker Desktop/Engine. - In the Docker tool window, click the
+button, chooseDocker Compose, and select thedocker-compose.ymlfile. - PhpStorm will list the services; verify they show a green status.
- Open
- Add a remote PHP interpreter pointing to the
appcontainer- Go to
Settings → PHP → CLI Interpreter. - Click the
+button, chooseFrom Docker, Vagrant, VM, WSL...→Docker. - Select the
laravel_appservice image (php:8.2-apache) and set theInterpreter pathto/usr/local/bin/php(default for the image). - Click
Test connection; a success dialog confirms PhpStorm can execute PHP inside the container. - Apply and set this interpreter as the project default.
- Go to
- Configure Xdebug for step‑through debugging
- Inside the
appcontainer, ensure Xdebug is installed (you can extend the Dockerfile or exec into the container and runpecl install xdebug). - Add a custom
php.inisnippet via a bind‑mount or Dockerfile:zend_extension=xdebug.so xdebug.mode=debug xdebug.start_with_request=yes xdebug.client_host=host.docker.internal xdebug.client_port=9003 - In PhpStorm, open
Settings → PHP → Debug, set the debug port to9003, and enableCan accept external connections. - Set a breakpoint in a controller method (e.g.,
app/Http/Controllers/WelcomeController.php). - Choose
Run → Debugand select the Docker‑based PHP interpreter; PhpStorm will launch a zero‑configuration debug session. - Make an HTTP request to
http://localhost:8000(via browser orcurl). The debugger should stop at the breakpoint, letting you inspect variables and step through code.
- Inside the
Trade‑off / Limitation: Startup overhead and learning curve
- Running PHP inside a container adds a few seconds of startup time compared to a native CLI interpreter.
- Team members must understand Docker Compose syntax and how to manage containers (e.g.,
docker compose logs,docker compose down). - Performance‑sensitive workloads (e.g., heavy CPU‑bound scripts) may feel slower due to the abstraction layer; consider using bind‑mounts for code and keeping only runtime dependencies inside the container.
Actionable closing: Commit configuration and onboard teammates
- Add
docker-compose.ymland any custom Dockerfiles to version control. - Commit the PhpStorm Docker configuration (the
.ideafolder contains Docker settings; they are safe to share). - When a new developer clones the repository, they only need to run
docker compose up -dand open the project in PhpStorm; the IDE will auto‑detect the Compose file and suggest the remote interpreter. - Verify the setup by creating a simple script (
php -r "echo 'Hello Docker\n';"), setting a breakpoint, and debugging as described above. - To tear down the environment, run
docker compose down -vfrom the project root; this stops containers and removes anonymous volumes, returning the system to a clean state.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.