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