For anyone following something like Pascal Landau's tutorial, here are some adjustments for doing the same, but using VSCodium instead of PHPStorm as your IDE of choice
These steps will help you use the PHP Interpreter running inside a specific docker container (in these steps, the PHP I want to use is located in a docker container called dofroscra_local-php-fpm-1)
- A single bash script we will use to run/debug the PHP code on our chosen docker container.
For the instructions below the location of this bash script will be shown as
/path/to/bash/script/php1
#!/bin/bash
container=$PHP_DOCKER_CONTAINER
if [ -z "$container" ]
then
container=$1
shift
fi
docker exec $container php $@- An entry to a
.envfile (in your existing project) to reference the name of the docker container. Instructions below are using the existing/.make/.env
PHP_DOCKER_CONTAINER=dofroscra_local-php-fpm-1NOTE: Use Workspace settings in VSCodium.
Add the executablePath settings to access PHP via our php bash script:
"php.validate.executablePath": "/path/to/bash/script/php",
"php.debug.executablePath": "/path/to/bash/script/php",Using the PHP Debug extension, add this to the Workspace settings:
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Run currently open script",
"type": "php",
"request": "launch",
"runtimeArgs": ["${env:PHP_DOCKER_CONTAINER} ${relativeFile}"],
"envFile": "${workspaceFolder}/.make/.env"
},
{
"name": "Debug currently open script",
"type": "php",
"request": "launch",
"port": 9003,
"runtimeArgs": ["${env:PHP_DOCKER_CONTAINER} ${relativeFile}"],
"pathMappings": {
"/var/www/app": "${workspaceFolder}",
},
"envFile": "${workspaceFolder}/.make/.env",
},
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/app": "${workspaceFolder}",
},
"envFile": "${workspaceFolder}/.make/.env"
},
{
"name": "Run PHPUnit tests",
"type": "php",
"request": "launch",
"runtimeArgs": [
"vendor/bin/phpunit --configuration phpunit.xml"
],
"envFile": "${workspaceFolder}/.make/.env"
}
]
}To access the PHP Interpreter we won't be needing ssh, but I've added the settings in the event it's needed.
Using the sshfs extension, add the following in your Workspace settings:
"settings": {
"sshfs.configs": [{
"root": "/var/www/app",
"host": "localhost",
"port": 2222,
"username": "application",
"password": "123456",
"name": "docker-php-tutorial_ssh"
}],
//settings from step 1 go here
},
//settings from step 2 go here{
"folders": [
{
"path": "docker-php-tutorial"
}
],
"settings": {
"sshfs.configs": [
{
"root": "/var/www/app",
"host": "localhost",
"port": 2222,
"username": "application",
"password": "123456",
"name": "docker-php-tutorial_ssh"
}
],
"php.validate.executablePath": "/path/to/bash/script/php",
"php.debug.executablePath": "/path/to/bash/script/php",
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Run currently open script",
"type": "php",
"request": "launch",
"runtimeArgs": ["${env:PHP_DOCKER_CONTAINER} ${relativeFile}"],
"envFile": "${workspaceFolder}/.make/.env"
},
{
"name": "Debug currently open script",
"type": "php",
"request": "launch",
"port": 9003,
"runtimeArgs": ["${env:PHP_DOCKER_CONTAINER} ${relativeFile}"],
"pathMappings": {
"/var/www/app": "${workspaceFolder}",
},
"envFile": "${workspaceFolder}/.make/.env",
},
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/app": "${workspaceFolder}",
},
"envFile": "${workspaceFolder}/.make/.env"
},
{
"name": "Run PHPUnit tests",
"type": "php",
"request": "launch",
"runtimeArgs": [
"vendor/bin/phpunit --configuration phpunit.xml"
],
"envFile": "${workspaceFolder}/.make/.env"
}
]
}
}Footnotes
-
The script will fall back to using the first parameter passed as the container name. So from the terminal you could do something like
~/location/php container_name -v"↩