Merge branch 'xdebugPhpFpm' of https://github.com/LarryEitel/laradock into LarryEitel-xdebugPhpFpm

* 'xdebugPhpFpm' of https://github.com/LarryEitel/laradock:
  Provided a way to Stop/Start php-fpm xdebug via bash script.
This commit is contained in:
Mahmoud Zalt 2016-08-16 15:13:42 +03:00
commit b4760ac703
8 changed files with 159 additions and 1 deletions

View File

@ -957,8 +957,12 @@ Use `http://127.0.0.1` instead of `http://localhost` in your browser.
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.
#### Stopping and Starting xdebug
By default, if you have chosen to install xDebug, it will be running/enabled on startup.
- To stop xdebug in the `php-fpm` container, from your laradock folder, run: `./xdebugPhpFpm stop`.
- To start, run: `./xdebugPhpFpm start`.
- To see php -v, run: `./xdebugPhpFpm status`.
<br>
<a name="upgrading-laradock"></a>

View File

@ -16,6 +16,11 @@ services:
- PGID=1000
volumes_from:
- volumes_source
extra_hosts:
# IMPORTANT: Replace with your Docker Host IP
# this will be appended to /etc/hosts
# Note that this IP can perhaps be better injected via .env
- "dockerhost:10.0.75.1"
tty: true
### PHP-FPM Container #######################################
@ -35,6 +40,17 @@ services:
- "9000"
links:
- workspace
extra_hosts:
# IMPORTANT: Replace with your Docker Host IP
# this will be appended to /etc/hosts
# Note that this IP can perhaps be better injected via .env
- "dockerhost:10.0.75.1"
environment:
# IMPORTANT: You must have a Remote Interpreter entry matching this name
# In settings, search for interpreter...
# PHP > Languages & Frameworks > PHP > Interpreter > click on [...]
# Need to have a Remote Interpreter named 'laravel'
- PHP_IDE_CONFIG="serverName=laravel"
### Nginx Server Container ##################################

View File

@ -50,6 +50,8 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \
pecl install xdebug && \
docker-php-ext-enable xdebug \
;fi
# ADD for REMOTE debugging
COPY ./xdebug_settings_only.ini /usr/local/etc/php/conf.d/xdebug_settings_only.ini
#####################################
# MongoDB:

View File

@ -50,6 +50,8 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \
pecl install xdebug && \
docker-php-ext-enable xdebug \
;fi
# ADD for REMOTE debugging
COPY ./xdebug_settings_only.ini /usr/local/etc/php/conf.d/xdebug_settings_only.ini
#####################################
# MongoDB:

View File

@ -0,0 +1,21 @@
; NOTE: The actual debug.so extention is NOT SET HERE but rather
; /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
; For example:
; zend_extension=xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
; In PHPStorm: Settings > Languages & Frameworks > PHP > Debug > Xdebug > Debug port
xdebug.remote_port=9000
; This is passed with by docker-compose / workspace / extra_hosts / - "dockerhost:10.0.75.1"
; It will set 10.0.75.1 dockerhost
; This will allow xdebug to connect to the host running PHPStorm.
xdebug.remote_host=dockerhost
; PHPStorm needs this
xdebug.idekey=PHPSTORM

View File

@ -52,6 +52,8 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \
sed -i 's/^/;/g' /etc/php/7.0/cli/conf.d/20-xdebug.ini && \
echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/laravel/vendor/bin/phpunit'" >> ~/.bashrc \
;fi
# ADD for REMOTE debugging
COPY ./xdebug_settings_only.ini /etc/php/7.0/cli/conf.d/xdebug_settings_only.ini
#####################################
# MongoDB:

View File

@ -0,0 +1,20 @@
; NOTE: The actual debug.so extention is NOT SET HERE but rather
; /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
; For example:
; zend_extension=xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
; In PHPStorm: Settings > Languages & Frameworks > PHP > Debug > Xdebug > Debug port
xdebug.remote_port=9000
; This is passed with by docker-compose / workspace / extra_hosts / - "dockerhost:10.0.75.1"
; It will set 10.0.75.1 dockerhost
; This will allow xdebug to connect to the host running PHPStorm.
xdebug.remote_host=dockerhost
; PHPStorm needs this
xdebug.idekey=PHPSTORM

91
xdebugPhpFpm Normal file
View File

@ -0,0 +1,91 @@
#! /bin/bash
# NOTE: At the moment, this has only been confirmed to work PHP 7
# Grab full name of php-fpm container
PHP_FPM_CONTAINER=$(docker-compose ps | grep php-fpm | cut -d" " -f 1)
xdebug_status ()
{
echo 'xDebug status'
# If running on Windows, need to prepend with winpty :(
if [[ "$(expr substr $(uname -s) 1 5)" == "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 [[ "$(expr substr $(uname -s) 1 5)" == "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 [[ "$(expr substr $(uname -s) 1 5)" == "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