Sign inSign up

zkucekovic/php-dev

By zkucekovic

•Updated about 1 year ago

PHP image with Composer, PHPUnit, and Xdebug. Intended for development or as a PHP shell alias.

Image
Languages & frameworks
0

1.3K

zkucekovic/php-dev repository overview

⁠PHP Development Docker Image

This Docker image provides a flexible PHP development environment with tools for debugging, testing, and code quality analysis. It's designed for developers who want to streamline their workflow with tools like Composer, PHPUnit, PHPStan, PHP CodeSniffer, PHP-CS-Fixer, and Xdebug.

⁠Key Features

  • Base Image: Built on the official php:8.x-cli.
  • Xdebug: Configured for debugging with PhpStorm or other IDEs.
  • Composer: Pre-installed for dependency management.
  • Development Tools: Includes PHPUnit, PHPStan, PHP CodeSniffer, and PHP-CS-Fixer.
  • Workdir: Map your local project directory to /app in the container.

⁠How to Use

docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 php <script_name>.php
docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 composer install
docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 phpunit
docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 phpstan analyse src
docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 phpcs src
docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 php-cs-fixer fix

⁠Example Shell Aliases

alias php='docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 php'
alias composer='docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 composer'
alias phpunit='docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 phpunit'
alias phpstan='docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 phpstan'
alias phpcs='docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 phpcs'
alias php-cs-fixer='docker run --rm -it -e XDEBUG_CLIENT_HOST=172.17.0.1 -p 9003:9003 -v $(pwd):/app zkucekovic/php-dev:8.4 php-cs-fixer'

⁠Setting Up Xdebug

This image comes with Xdebug pre-installed and configured for remote debugging. Follow these steps to set up and use Xdebug:

⁠1. Configure PhpStorm
  1. Go to Settings > PHP > Debug:

    • Set the Debug Port to 9003 (default for Xdebug 3).
  2. Use "host.docker.internal" as the client host for macOS/Windows or your system's IP (e.g., 172.17.0.1) on Linux.

  3. Enable path mappings under Settings > PHP > Servers:

    • Map /app in the container to your local project directory.

⁠Setting Up Xdebug

This image comes with Xdebug pre-installed and configured for remote debugging. Follow these steps to set up and use Xdebug:

⁠1. Configure PhpStorm
  1. Go to Settings > PHP > Debug:
    • Set the Debug Port to 9003 (default for Xdebug 3).
  2. Use "host.docker.internal" as the client host for macOS/Windows or your system's IP (e.g., 172.17.0.1) on Linux.
  3. Enable path mappings under Settings > PHP > Servers:
    • Map /app in the container to your local project directory.
⁠2. Run the Container with Xdebug Enabled

Run the container, passing the XDEBUG_CLIENT_HOST environment variable to specify the host's IP address:

docker run --rm -it \
    -e XDEBUG_CLIENT_HOST=<host_ip> \
    -p 9003:9003 \
    -v $(pwd):/app \
    zkucekovic/php-dev:8.4 php <script_name>.php

Replace <host_ip> with:

  • host.docker.internal (macOS/Windows)
  • 172.17.0.1 (Linux, or the IP of your Docker bridge network)

Tag summary

Content type

Image

Digest

sha256:83523b01d…

Size

219.1 MB

Last updated

over 1 year ago

docker pull zkucekovic/php-dev