Docker for #PHP with @Xdebug and @phpstorm is (or was) a bit tricky to setup. 🐞🐞🐞

Here is a sample you can use:
* no Dockerfile needed
* composer for build jobs
* code execution with phpunit

A thread! 🧵👇
Instead of creating our own Dockerfile we use webdevops/php-dev image, which already comes with Xdebug (and other tools like blackfire) installed.


If you wonder about the path mapping:
docker-compose.yaml and .env live in a subfolder in this example.
We map a local .env file for configuration. This will create these environment variables "inside" the docker container.

Now run the following commands to create/run the containers:
`docker-compose pull`
`docker-compose up -d`

no build required, as we use a pre-build image
If you are on linux, check this little additional info: https://twitter.com/fn_schubert/status/1356310433674752003?s=20
As you might spotted, Xdebug is “off“ by default. So we need to enable it. Therefore create 2 entries in the “scripts“ section of composer.json.

with `composer test` Xdebug will only create coverage
with `composer test-debug` Xdebug will call Phpstorm to step debug
But first we need to setup a Server in Phpstorm. Open Preferences and then go to
Languages & Frameworks > PHP > Servers

Add a new one with:
name: must be the same as specified in .env file
host: localhost or 0.0.0.0
port: doesn’t matter
path mapping: map absolute path /app
In the right top click on the little button that says on hover "Start listening for debug connections"

After that run:
`docker exec -it rest-php74 composer test-debug`

rest-php74 is the container_name specified in docker-compose
You can follow @fn_schubert.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.