Skip to content

Commit d8a4537

Browse files
committed
Provided a way to Stop/Start php-fpm xdebug via bash script.
1 parent 28b4077 commit d8a4537

8 files changed

Lines changed: 159 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,12 @@ Use `http://127.0.0.1` instead of `http://localhost` in your browser.
957957

958958
Make sure the ports for the services that you are trying to run (80, 3306, etc.) are not being used already by other programs, such as a built in `apache`/`httpd` service or other development tools you have installed.
959959

960+
#### Stopping and Starting xdebug
960961

961-
962+
By default, if you have chosen to install xDebug, it will be running/enabled on startup.
963+
- To stop xdebug in the `php-fpm` container, from your laradock folder, run: `./xdebugPhpFpm stop`.
964+
- To start, run: `./xdebugPhpFpm start`.
965+
- To see php -v, run: `./xdebugPhpFpm status`.
962966

963967
<br>
964968
<a name="upgrading-laradock"></a>

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ services:
1616
- PGID=1000
1717
volumes_from:
1818
- volumes_source
19+
extra_hosts:
20+
# IMPORTANT: Replace with your Docker Host IP
21+
# this will be appended to /etc/hosts
22+
# Note that this IP can perhaps be better injected via .env
23+
- "dockerhost:10.0.75.1"
1924
tty: true
2025

2126
### PHP-FPM Container #######################################
@@ -34,6 +39,17 @@ services:
3439
- "9000"
3540
links:
3641
- workspace
42+
extra_hosts:
43+
# IMPORTANT: Replace with your Docker Host IP
44+
# this will be appended to /etc/hosts
45+
# Note that this IP can perhaps be better injected via .env
46+
- "dockerhost:10.0.75.1"
47+
environment:
48+
# IMPORTANT: You must have a Remote Interpreter entry matching this name
49+
# In settings, search for interpreter...
50+
# PHP > Languages & Frameworks > PHP > Interpreter > click on [...]
51+
# Need to have a Remote Interpreter named 'laravel'
52+
- PHP_IDE_CONFIG="serverName=laravel"
3753

3854
### Nginx Server Container ##################################
3955

php-fpm/Dockerfile-56

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \
4949
pecl install xdebug && \
5050
docker-php-ext-enable xdebug \
5151
;fi
52+
# ADD for REMOTE debugging
53+
COPY ./xdebug_settings_only.ini /usr/local/etc/php/conf.d/xdebug_settings_only.ini
5254

5355
#####################################
5456
# MongoDB:

php-fpm/Dockerfile-70

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \
4949
pecl install xdebug && \
5050
docker-php-ext-enable xdebug \
5151
;fi
52+
# ADD for REMOTE debugging
53+
COPY ./xdebug_settings_only.ini /usr/local/etc/php/conf.d/xdebug_settings_only.ini
5254

5355
#####################################
5456
# MongoDB:

php-fpm/xdebug_settings_only.ini

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; NOTE: The actual debug.so extention is NOT SET HERE but rather
2+
; /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
3+
; For example:
4+
; zend_extension=xdebug.so
5+
6+
xdebug.remote_autostart=1
7+
xdebug.remote_enable=1
8+
xdebug.remote_handler=dbgp
9+
xdebug.remote_mode=req
10+
11+
; In PHPStorm: Settings > Languages & Frameworks > PHP > Debug > Xdebug > Debug port
12+
xdebug.remote_port=9000
13+
14+
; This is passed with by docker-compose / workspace / extra_hosts / - "dockerhost:10.0.75.1"
15+
; It will set 10.0.75.1 dockerhost
16+
; This will allow xdebug to connect to the host running PHPStorm.
17+
xdebug.remote_host=dockerhost
18+
19+
; PHPStorm needs this
20+
xdebug.idekey=PHPSTORM
21+

workspace/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \
5252
sed -i 's/^/;/g' /etc/php/7.0/cli/conf.d/20-xdebug.ini && \
5353
echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/laravel/vendor/bin/phpunit'" >> ~/.bashrc \
5454
;fi
55+
# ADD for REMOTE debugging
56+
COPY ./xdebug_settings_only.ini /etc/php/7.0/cli/conf.d/xdebug_settings_only.ini
5557

5658
#####################################
5759
# MongoDB:

workspace/xdebug_settings_only.ini

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; NOTE: The actual debug.so extention is NOT SET HERE but rather
2+
; /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
3+
; For example:
4+
; zend_extension=xdebug.so
5+
6+
xdebug.remote_autostart=1
7+
xdebug.remote_enable=1
8+
xdebug.remote_handler=dbgp
9+
xdebug.remote_mode=req
10+
11+
; In PHPStorm: Settings > Languages & Frameworks > PHP > Debug > Xdebug > Debug port
12+
xdebug.remote_port=9000
13+
14+
; This is passed with by docker-compose / workspace / extra_hosts / - "dockerhost:10.0.75.1"
15+
; It will set 10.0.75.1 dockerhost
16+
; This will allow xdebug to connect to the host running PHPStorm.
17+
xdebug.remote_host=dockerhost
18+
19+
; PHPStorm needs this
20+
xdebug.idekey=PHPSTORM

xdebugPhpFpm

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#! /bin/bash
2+
3+
# NOTE: At the moment, this has only been confirmed to work PHP 7
4+
5+
6+
# Grab full name of php-fpm container
7+
PHP_FPM_CONTAINER=$(docker-compose ps | grep php-fpm | cut -d" " -f 1)
8+
9+
xdebug_status ()
10+
{
11+
echo 'xDebug status'
12+
13+
# If running on Windows, need to prepend with winpty :(
14+
if [[ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]]; then
15+
winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
16+
17+
else
18+
docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
19+
fi
20+
21+
}
22+
23+
xdebug_start ()
24+
{
25+
echo 'Start xDebug'
26+
27+
# And uncomment line with xdebug extension, thus enabling it
28+
ON_CMD="sed -i 's/^;zend_extension=/zend_extension=/g' \
29+
/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
30+
31+
32+
# If running on Windows, need to prepend with winpty :(
33+
if [[ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]]; then
34+
winpty docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}"
35+
docker restart $PHP_FPM_CONTAINER
36+
winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
37+
38+
else
39+
docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}"
40+
docker restart $PHP_FPM_CONTAINER
41+
docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
42+
fi
43+
44+
}
45+
46+
xdebug_stop ()
47+
{
48+
echo 'Stop xDebug'
49+
50+
# Comment out xdebug extension line
51+
OFF_CMD="sed -i 's/^zend_extension=/;zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
52+
53+
54+
# If running on Windows, need to prepend with winpty :(
55+
if [[ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]]; then
56+
# This is the equivalent of:
57+
# winpty docker exec -it laradock_php-fpm_1 bash -c 'bla bla bla'
58+
# Thanks to @michaelarnauts at https://github.com/docker/compose/issues/593
59+
winpty docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}"
60+
docker restart $PHP_FPM_CONTAINER
61+
#docker-compose restart php-fpm
62+
winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
63+
64+
else
65+
docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}"
66+
# docker-compose restart php-fpm
67+
docker restart $PHP_FPM_CONTAINER
68+
docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
69+
fi
70+
}
71+
72+
73+
case $@ in
74+
stop|STOP)
75+
xdebug_stop
76+
;;
77+
start|START)
78+
xdebug_start
79+
;;
80+
status|STATUS)
81+
xdebug_status
82+
;;
83+
*)
84+
echo "xDebug [Stop | Start | Status] in the ${PHP_FPM_CONTAINER} container."
85+
echo "xDebug must have already been installed."
86+
echo "Usage:"
87+
echo " ./xdebugPhpFpm stop|start|status"
88+
89+
esac
90+
91+
exit 1

0 commit comments

Comments
 (0)