Skip to content

Commit 2d8621a

Browse files
committed
adjust development example, added xdebug
1 parent e8b6c3b commit 2d8621a

File tree

5 files changed

+77
-34
lines changed

5 files changed

+77
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,4 @@ git commit -m "Description of changes"
239239

240240
## License
241241

242-
This project is licensed under the MIT License. See the [LICENSE]LICENSE file for more details.
242+
This project is licensed under the MIT License. See the LICENSE file for more details.

development/nginx-fpm/compose.yaml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,54 @@
11
services:
22
web:
33
image: nginx:latest # We don't need to customize the image. Just pass the configuration to the Dockerfile.
4-
networks:
5-
- laravel
64
volumes:
7-
- ${LARAVEL_APP_PATH}/nginx.conf:/etc/nginx/nginx.conf:ro # Mount the nginx.conf file directly
5+
# Mount the application code for live updates
86
- ${LARAVEL_APP_PATH}:/var/www
7+
# Mount the Nginx configuration file
8+
- ${LARAVEL_APP_PATH}/nginx.conf:/etc/nginx/nginx.conf:ro
99
ports:
10+
# Map port 80 inside the container to the port specified by 'NGINX_PORT' on the host machine
1011
- "${NGINX_PORT}:80"
1112
environment:
1213
- NGINX_HOST=${NGINX_HOST}
14+
networks:
15+
- laravel
16+
depends_on:
17+
php-fpm:
18+
condition: service_started # Wait for php-fpm to start
1319

1420
php-fpm:
1521
# For the php-fpm service, we will create a custom image to install the necessary PHP extensions and setup proper permissions.
1622
build:
17-
context: ./php-fpm
18-
dockerfile: Dockerfile
23+
context: ../../example-app
24+
dockerfile: ../development/nginx-fpm/php-fpm/Dockerfile
1925
args:
2026
UID: ${UID}
2127
GID: ${GID}
2228
env_file:
29+
# Load the environment variables from the Laravel application
2330
- ${LARAVEL_APP_PATH}/.env
2431
volumes:
32+
# Mount the application code for live updates
2533
- ${LARAVEL_APP_PATH}:/var/www
34+
ports:
35+
- "9004:9003" # Xdebug port
2636
networks:
2737
- laravel
38+
depends_on:
39+
postgres:
40+
condition: service_started # Wait for postgres to start
2841

2942
workspace:
3043
# For the workspace service, we will also create a custom image to install and setup all the necessary stuff.
3144
build:
32-
context: ./workspace
33-
dockerfile: Dockerfile
45+
context: ../../example-app
46+
dockerfile: ../development/nginx-fpm/workspace/Dockerfile
3447
args:
3548
UID: ${UID}
3649
GID: ${GID}
37-
tty: true # Keep the terminal open
38-
stdin_open: true # Keep stdin open to attach to the container
50+
tty: true # Enables an interactive terminal
51+
stdin_open: true # Keeps standard input open for 'docker exec'
3952
env_file:
4053
- ${LARAVEL_APP_PATH}/.env
4154
volumes:
@@ -46,11 +59,11 @@ services:
4659
postgres:
4760
image: postgres:16
4861
ports:
49-
- "5432:5432"
62+
- "${POSTGRES_PORT}:5432"
5063
environment:
51-
- POSTGRES_DB=${DB_DATABASE}
52-
- POSTGRES_USER=${DB_USERNAME}
53-
- POSTGRES_PASSWORD=${DB_PASSWORD}
64+
- POSTGRES_DB=${POSTGRES_DATABASE}
65+
- POSTGRES_USER=${POSTGRES_USERNAME}
66+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
5467
volumes:
5568
- postgres-data:/var/lib/postgresql/data
5669
networks:

development/nginx-fpm/php-fpm/Dockerfile

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
1-
# Stage 1: Build environment
2-
FROM php:8.3-fpm AS builder
1+
# For development environment we can use one-stage build for simplicity.
2+
FROM php:8.3-fpm
33

4-
# Install system dependencies and build libraries
4+
# Install system dependencies and PHP extensions required for Laravel + MySQL/PostgreSQL support
5+
# Some dependencies are required for PHP extensions only in the build stage
6+
# We don't need to install Node.js or build assets, as it was done in the Nginx image
57
RUN apt-get update && apt-get install -y --no-install-recommends \
68
curl \
7-
# libpq-dev is required for PostgreSQL
9+
unzip \
810
libpq-dev \
911
libonig-dev \
1012
libssl-dev \
1113
libxml2-dev \
1214
libcurl4-openssl-dev \
15+
libicu-dev \
16+
libzip-dev \
1317
&& docker-php-ext-install -j$(nproc) \
14-
# PHP Extensions required for Laravel. See https://laravel.com/docs/11.x/deployment#server-requirements
15-
# Most of these extensions are already included in the base image.
18+
pdo_mysql \
1619
pdo_pgsql \
1720
pgsql \
18-
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
19-
20-
# Stage 2: Runtime environment
21-
FROM php:8.3-fpm
21+
opcache \
22+
intl \
23+
zip \
24+
bcmath \
25+
soap \
26+
&& pecl install redis xdebug \
27+
&& docker-php-ext-enable redis xdebug\
28+
&& apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
29+
30+
# Configure Xdebug by appending settings to the existing INI file
31+
RUN echo "xdebug.mode=develop,coverage,debug,profile" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
32+
&& echo "xdebug.idekey=docker" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
33+
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
34+
&& echo "xdebug.log=/dev/stdout" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
35+
&& echo "xdebug.log_level=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
36+
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
37+
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
38+
39+
# Copy the initialization script
40+
COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh
41+
RUN chmod +x /usr/local/bin/entrypoint.sh
2242

2343
# Set environment variables for user and group ID
2444
ARG UID=1000
@@ -28,17 +48,14 @@ ARG GID=1000
2848
RUN groupadd -g ${GID} www && \
2949
useradd -u ${UID} -g www -m www
3050

31-
# Copy only the necessary PHP extensions from the build stage
32-
COPY --from=builder /usr/local/lib/php/extensions/no-debug-non-zts-*/ /usr/local/lib/php/extensions/no-debug-non-zts-*/
33-
3451
# Set working directory
3552
WORKDIR /var/www
3653

3754
# Change ownership of the working directory to the new user
3855
RUN chown -R www:www /var/www
3956

40-
# Switch to the non-root user
41-
USER www
57+
# Change the default command to run the entrypoint script
58+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
4259

4360
# Expose port 9000 and start php-fpm server
4461
EXPOSE 9000

development/nginx-fpm/workspace/Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ ARG GID=1000
77
ARG NODE_VERSION=22.0.0
88

99
# Install system dependencies and build libraries
10-
RUN apt-get update && apt-get install -y \
10+
RUN apt-get update && apt-get install -y --no-install-recommends \
1111
curl \
12-
git \
13-
sudo \
1412
unzip \
1513
libpq-dev \
1614
libonig-dev \
@@ -19,9 +17,19 @@ RUN apt-get update && apt-get install -y \
1917
libcurl4-openssl-dev \
2018
libicu-dev \
2119
libzip-dev \
20+
&& docker-php-ext-install -j$(nproc) \
21+
pdo_mysql \
22+
pdo_pgsql \
23+
pgsql \
24+
opcache \
25+
intl \
26+
zip \
27+
bcmath \
28+
soap \
29+
&& pecl install redis xdebug \
30+
&& docker-php-ext-enable redis xdebug\
2231
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
23-
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash \
24-
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
32+
&& apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
2533

2634
# Create a user with the same UID and GID as the host user
2735
RUN groupadd -g ${GID} www && \

example-app/routes/web.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
return view('welcome');
88
});
99

10+
Route::get('/info', function () {
11+
Log::info('Phpinfo page visited');
12+
return phpinfo();
13+
});
14+
1015
Route::get('/health', function () {
1116
$status = [];
1217

0 commit comments

Comments
 (0)