Skip to content

Commit f497cbb

Browse files
committed
init commit
1 parent 3435446 commit f497cbb

9 files changed

Lines changed: 219 additions & 0 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# php-xdebug-docker
22
Flip between non xdebug local dev (much fast) to xdebug local dev (not fast but much insights) at the flick of a cookie (single click via xdebug browser extension). by @jenkoian
3+
4+
Setup
5+
6+
1. Create a docker network:
7+
`docker network create --subnet=192.168.50.0/24 pxd-docker`
8+
2. Add `127.0.0.1 php-xdebug-docker` to your hosts file.
9+
3. Run `docker-compose up -d` to start the env

docker-compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
context: docker/app
7+
dockerfile: Dockerfile
8+
args:
9+
USER_ID: ${USER_ID:-0}
10+
GROUP_ID: ${GROUP_ID:-0}
11+
env_file:
12+
- ./docker/app/.env
13+
volumes:
14+
- '.:/var/www/html/:delegated'
15+
16+
app_xdebug:
17+
build:
18+
context: docker/app
19+
dockerfile: Dockerfile_xdebug
20+
args:
21+
USER_ID: ${USER_ID:-0}
22+
GROUP_ID: ${GROUP_ID:-0}
23+
env_file:
24+
- ./docker/app/.env
25+
volumes:
26+
- '.:/var/www/html/:delegated'
27+
28+
nginx:
29+
image: nginx
30+
volumes:
31+
- '.:/var/www/html/'
32+
- './docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf'
33+
ports:
34+
- '127.0.0.1:80:80'
35+
36+
networks:
37+
default:
38+
external:
39+
name: 'pxd-docker'

docker/app/.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PHP_XDEBUG_ENABLED=1
2+
PHP_XDEBUG_REMOTE_PORT=9002
3+
# Xdebug remote host likely 192.168.50.1 if on linux, use host.docker.internal on a Mac
4+
PHP_XDEBUG_REMOTE_HOST=192.168.50.1
5+
PHP_XDEBUG_IDKEY=pxd
6+
PHP_MEMORY_LIMIT=1G
7+
8+
APP_ENV=dev
9+
PHP_IDE_CONFIG="serverName=pxd"

docker/app/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM php:7.3-fpm
2+
3+
ARG USER_ID
4+
ARG GROUP_ID
5+
6+
RUN if [ ${USER_ID:-0} -ne 0 ] && [ ${GROUP_ID:-0} -ne 0 ]; then \
7+
userdel -f www-data &&\
8+
if getent group www-data ; then groupdel www-data; fi &&\
9+
groupadd -g ${GROUP_ID} www-data &&\
10+
useradd -l -u ${USER_ID} -g www-data www-data &&\
11+
install -d -m 0755 -o www-data -g www-data /home/www-data\
12+
;fi
13+
14+
COPY ./php/php.ini /usr/local/etc/php/conf.d/zzz_app.ini
15+
16+
RUN rm -rf /var/lib/apt/lists/*
17+
18+
WORKDIR /var/www/html
19+
20+
RUN chown -R www-data:www-data /var/www
21+
22+
EXPOSE 9000
23+
CMD ["php-fpm"]

docker/app/Dockerfile_xdebug

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM php:7.3-fpm
2+
3+
ARG USER_ID
4+
ARG GROUP_ID
5+
6+
# Xdebug
7+
RUN pecl install xdebug && docker-php-ext-enable xdebug
8+
9+
RUN if [ ${USER_ID:-0} -ne 0 ] && [ ${GROUP_ID:-0} -ne 0 ]; then \
10+
userdel -f www-data &&\
11+
if getent group www-data ; then groupdel www-data; fi &&\
12+
groupadd -g ${GROUP_ID} www-data &&\
13+
useradd -l -u ${USER_ID} -g www-data www-data &&\
14+
install -d -m 0755 -o www-data -g www-data /home/www-data\
15+
;fi
16+
17+
COPY ./php/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
18+
COPY ./php/php.ini /usr/local/etc/php/conf.d/zzz_app.ini
19+
20+
RUN rm -rf /var/lib/apt/lists/*
21+
22+
WORKDIR /var/www/html
23+
24+
RUN chown -R www-data:www-data /var/www
25+
26+
EXPOSE 9000
27+
CMD ["php-fpm"]

docker/app/php/php.ini

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[php]
2+
post_max_size = 10M
3+
upload_max_filesize = 10M
4+
log_errors = On
5+
memory_limit = ${PHP_MEMORY_LIMIT}
6+
expose_php = Off
7+
date.timezone = UTC
8+
9+
short_open_tag = Off
10+
magic_quotes_gpc = Off
11+
register_globals = Off
12+
session.auto_start = Off
13+
html_errors = Off
14+
15+
realpath_cache_size=8M
16+
realpath_cache_ttl=14400
17+
18+
cgi.fix_pathinfo = 0;

docker/app/php/xdebug.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[xdebug]
2+
xdebug.default_enable=${PHP_XDEBUG_ENABLED}
3+
xdebug.max_nesting_level=256
4+
5+
xdebug.remote_enable=1
6+
xdebug.remote_autostart=1
7+
xdebug.remote_host=${PHP_XDEBUG_REMOTE_HOST}
8+
xdebug.remote_port=${PHP_XDEBUG_REMOTE_PORT}
9+
xdebug.idekey=${PHP_XDEBUG_IDKEY}

docker/nginx/nginx.conf

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# default Docker DNS server
2+
resolver 127.0.0.11;
3+
4+
# idea from https://github.com/developersalliance/magento2-dockergento/blob/master/config/dockergento/nginx/conf/default.conf
5+
map $cookie_XDEBUG_SESSION $fastcgi_pass {
6+
default app;
7+
wordpress app_xdebug;
8+
}
9+
10+
server {
11+
listen 80 default_server;
12+
listen [::]:80 default_server;
13+
14+
server_name php-xdebug-docker;
15+
root /var/www/html;
16+
17+
index index.php;
18+
19+
# https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/web_performance/compression.conf
20+
gzip on;
21+
gzip_vary on;
22+
gzip_proxied any;
23+
gzip_comp_level 5;
24+
gzip_buffers 16 8k;
25+
gzip_min_length 256;
26+
gzip_types
27+
application/atom+xml
28+
application/geo+json
29+
application/javascript
30+
application/x-javascript
31+
application/json
32+
application/ld+json
33+
application/manifest+json
34+
application/rdf+xml
35+
application/rss+xml
36+
application/vnd.ms-fontobject
37+
application/wasm
38+
application/x-web-app-manifest+json
39+
application/xhtml+xml
40+
application/xml
41+
font/eot
42+
font/otf
43+
font/ttf
44+
image/bmp
45+
image/svg+xml
46+
text/cache-manifest
47+
text/calendar
48+
text/css
49+
text/javascript
50+
text/markdown
51+
text/plain
52+
text/xml
53+
text/vcard
54+
text/vnd.rim.location.xloc
55+
text/vtt
56+
text/x-component
57+
text/x-cross-domain-policy;
58+
59+
location / {
60+
try_files $uri $uri/ /index.php?$args;
61+
}
62+
63+
location ~ \.php$ {
64+
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
65+
include fastcgi_params;
66+
fastcgi_intercept_errors on;
67+
fastcgi_pass $fastcgi_pass:9000;
68+
69+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
70+
fastcgi_index index.php;
71+
72+
fastcgi_param PATH_INFO $fastcgi_path_info;
73+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
74+
fastcgi_param DOCUMENT_ROOT $realpath_root;
75+
}
76+
77+
client_max_body_size 10M;
78+
79+
error_log /var/log/nginx/error.log;
80+
access_log /var/log/nginx/access.log;
81+
}

index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
$test = 'Hello World!';
5+
6+
echo $test; # put a breakpoint on this line :-)

0 commit comments

Comments
 (0)