Skip to content

Commit 6fac2a2

Browse files
committed
OP-289: Add xdebug support for docker
1 parent 4903ee2 commit 6fac2a2

5 files changed

Lines changed: 110 additions & 6 deletions

File tree

File renamed without changes.

.docker/Dockerfile-xdebug

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
FROM ubuntu:20.04
2+
ARG DEBIAN_FRONTEND=noninteractive
3+
ARG PHP_VERSION=8.1
4+
ENV LC_ALL=C.UTF-8
5+
6+
# Install basic tools
7+
RUN apt-get update && apt-get install -y \
8+
software-properties-common \
9+
curl \
10+
make \
11+
supervisor \
12+
unzip \
13+
python2 \
14+
g++
15+
16+
# Append NODE, NGINX and PHP repositories
17+
RUN add-apt-repository ppa:ondrej/php \
18+
&& add-apt-repository ppa:ondrej/nginx \
19+
&& curl -sL https://deb.nodesource.com/setup_14.x | bash -
20+
21+
# Install required PHP extensions
22+
RUN apt-get update && apt-get install -y \
23+
nodejs \
24+
nginx \
25+
php${PHP_VERSION} \
26+
php${PHP_VERSION}-apcu \
27+
php${PHP_VERSION}-calendar \
28+
php${PHP_VERSION}-common \
29+
php${PHP_VERSION}-cli \
30+
php${PHP_VERSION}-ctype \
31+
php${PHP_VERSION}-curl \
32+
php${PHP_VERSION}-dom \
33+
php${PHP_VERSION}-exif \
34+
php${PHP_VERSION}-fpm \
35+
php${PHP_VERSION}-gd \
36+
php${PHP_VERSION}-intl \
37+
php${PHP_VERSION}-mbstring \
38+
php${PHP_VERSION}-mysql \
39+
php${PHP_VERSION}-opcache \
40+
php${PHP_VERSION}-pdo \
41+
php${PHP_VERSION}-pgsql \
42+
php${PHP_VERSION}-sqlite \
43+
php${PHP_VERSION}-xml \
44+
php${PHP_VERSION}-xsl \
45+
php${PHP_VERSION}-yaml \
46+
php${PHP_VERSION}-xdebug \
47+
php${PHP_VERSION}-zip
48+
49+
# Install Composer
50+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename composer
51+
52+
# Cleanup
53+
RUN apt-get remove --purge -y software-properties-common curl && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* /usr/share/man/*
54+
55+
# Create directory for php-fpm socket
56+
# Link php-fpm binary file without version
57+
# -p Creates missing intermediate path name directories
58+
RUN ln -s /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm && mkdir -p /run/php
59+
60+
# Install yarn
61+
RUN npm install -g yarn && npm cache clean --force
62+
63+
# Initialize config files
64+
COPY .docker/supervisord.conf /etc/supervisor/conf.d/supervisor.conf
65+
COPY .docker/nginx.conf /etc/nginx/nginx.conf
66+
COPY .docker/fpm.conf /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf
67+
COPY .docker/php-xdebug.ini /etc/php/${PHP_VERSION}/fpm/php.ini
68+
COPY .docker/php-xdebug.ini /etc/php/${PHP_VERSION}/cli/php.ini
69+
70+
WORKDIR /app
71+
72+
EXPOSE 80
73+
74+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]

.docker/php-xdebug.ini

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[PHP]
2+
memory_limit=512M
3+
4+
[date]
5+
date.timezone=${PHP_DATE_TIMEZONE}
6+
7+
[opcache]
8+
opcache.enable=0
9+
opcache.memory_consumption=256
10+
opcache.max_accelerated_files=20000
11+
opcache.validate_timestamps=0
12+
;opcache.preload=/app/config/preload.php
13+
opcache.preload_user=www-data
14+
opcache.jit=1255
15+
opcache.jit_buffer_size=256M
16+
17+
[xdebug]
18+
xdebug.mode=debug
19+
xdebug.client_host=host.docker.internal
20+
xdebug.start_with_request = yes
21+
xdebug.client_port = 9003
22+
xdebug.discover_client_host = 1

.docker/php.ini

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ opcache.preload_user=www-data
1414
opcache.jit=1255
1515
opcache.jit_buffer_size=256M
1616

17-
;[xdebug]
18-
;xdebug.mode=debug
19-
;xdebug.client_host=host.docker.internal
20-
;xdebug.start_with_request = yes
21-
;xdebug.client_port = 9003
17+
[xdebug]
18+
xdebug.mode=debug
19+
xdebug.client_host=host.docker.internal
20+
xdebug.start_with_request = yes
21+
xdebug.client_port = 9003
22+
xdebug.discover_client_host = 1

docker-compose.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ services:
33
container_name: app
44
build:
55
context: .
6+
dockerfile: .docker/Dockerfile
7+
# dockerfile: .docker/Dockerfile-xdebug
68
environment:
79
APP_ENV: "dev"
810
DATABASE_URL: "mysql://root:mysql@mysql/sylius_%kernel.environment%?charset=utf8mb4"
911
# DATABASE_URL: "pgsql://root:postgres@postgres/sylius_%kernel.environment%?charset=utf8" # When using postgres
1012
PHP_DATE_TIMEZONE: "Europe/Warsaw"
11-
# PHP_IDE_CONFIG: serverName=wishlist
13+
PHP_IDE_CONFIG: serverName=PHPSTORM
1214
volumes:
1315
- ./:/app:delegated
1416
- ./.docker/php.ini:/etc/php8/php.ini:delegated
@@ -24,6 +26,8 @@ services:
2426
container_name: mysql
2527
image: mysql:8.0
2628
platform: linux/amd64
29+
volumes:
30+
- mysql-data:/var/lib/mysql:rw
2731
environment:
2832
MYSQL_ROOT_PASSWORD: mysql
2933
ports:
@@ -44,3 +48,6 @@ services:
4448
networks:
4549
sylius:
4650
driver: bridge
51+
52+
volumes:
53+
mysql-data:

0 commit comments

Comments
 (0)