Skip to content

Instantly share code, notes, and snippets.

@fhuitelec
Last active January 4, 2018 14:47
Show Gist options
  • Save fhuitelec/943fa4282ced38f83a3b8bf879e2e0e7 to your computer and use it in GitHub Desktop.
Save fhuitelec/943fa4282ced38f83a3b8bf879e2e0e7 to your computer and use it in GitHub Desktop.
[Bootstrap simple xdebug dev stack] #php #debug #docker #makefile

Getting started

Initialization

  1. Copy docker-compose .env file
cp .env.dist .env
  1. Create alias interface (tested on macOS only)
# Arbitrary A class IP address
# Careful to collisions
sudo ifconfig lo0 alias 10.0.2.2
  1. Add REMOTE_HOST=10.0.2.2 in .env

Running

# You're all set, run your tests
make unit
REMOTE_HOST=
PHP_VERSION=7.1
PROJECT_NAME="Your project name here"
FORMATTED_PROJECT_NAME="your-project-name-here"
version: '3.1'
services:
php:
build:
context: .
dockerfile: dev.Dockerfile
args:
PHP_VERSION: ${PHP_VERSION}
environment:
XDEBUG_CONFIG: 'remote_host=${REMOTE_HOST}'
PHP_IDE_CONFIG: 'serverName=${FORMATTED_PROJECT_NAME}'
network_mode: bridge
volumes:
- .:/app
working_dir: /app
ARG PHP_VERSION
FROM php:${PHP_VERSION}-cli-alpine
RUN apk --update add --no-cache --virtual .build-deps autoconf alpine-sdk \
&& pecl install xdebug-2.5.0 \
&& docker-php-ext-enable xdebug \
&& apk del .build-deps
RUN touch /usr/local/etc/php/php.ini
RUN echo 'xdebug.remote_enable=1' >> /usr/local/etc/php/php.ini
RUN echo 'date.timezone = "Europe/Paris"' >> /usr/local/etc/php/php.ini
.PHONY: unit
unit:
$(DOCKER_EXEC) ./vendor/bin/phpunit
# ######### #
# INTERNALS #
# ######### #
# Docker partial commands
export DOCKER_EXEC = docker-compose -f ./docker-compose.dev.yaml \
run --rm --name=${PROJECT_ID} php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment