├── composer.json ├── LICENSE ├── README.md └── phpdebug.sh /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dbalabka/phpdebug-cli", 3 | "description": "XDebug and Zend Debugger PHP CLI debugging helper console command with PhpStorm, NetBeans support", 4 | "license": ["MIT"], 5 | "suggest": { 6 | "ext-xdebug": "You require X-Debug extension to perform CLI scrips debugging." 7 | }, 8 | "bin": ["phpdebug.sh"] 9 | } 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Dmitry Balabka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phpdebug-cli 2 | XDebug PHP CLI debugging helper console command with PhpStorm, NetBeans support 3 | 4 | # Installation steps 5 | 1. Donwload file into ~/.phpdebug. Run following command: 6 | ```bash 7 | curl https://raw.githubusercontent.com/torinaki/phpdebug-cli/master/phpdebug.sh > ~/.phpdebug 8 | ``` 9 | 2. Put following lines into ~/.bashrc : 10 | ```bash 11 | # Get the aliases and functions 12 | if [ -f ~/.phpdebug ]; then 13 | . ~/.phpdebug 14 | fi 15 | ``` 16 | 3. (optional) Script will try to autodetect your machine IP where runs IDE or use 127.0.0.1 otherwise. 17 | If automatic detection doesn't work for you, set ip directly via IDE_IP enviroment variable: 18 | ```bash 19 | export IDE_IP=1.2.3.4 20 | ``` 21 | 4. (optional) Change ports if it not same as default (see local variables zend_debugger_config and xdebug_config); 22 | ```bash 23 | export IDE_ZEND_PORT=10137 24 | export IDE_ZDEBUG_PORT=9000 25 | ``` 26 | 5. (optional) Change IDE specific configuration: serverName, idekey 27 | ```bash 28 | export IDE_SERVERNAME="Any_server_name" 29 | export IDE_KEY="PHPSTORM" 30 | ``` 31 | 6. Run use it immediately or just restart terminal: 32 | ```bash 33 | source ~/.bashrc 34 | ``` 35 | 36 | # Usage 37 | 1. After installation use phpdebug/phpdebugoff commands to start/stop debugging: 38 | ```bash 39 | $ phpdebug 40 | $ php ./script1_to_debug.php 41 | $ php ./script2_to_debug.php 42 | $ phpdebugoff 43 | ``` 44 | 2. Or simply use instead of php command to debug only one script 45 | ```bash 46 | $ phpdebug -dmemory_limit=1G ./script_to_debug.php 47 | ``` 48 | 49 | # Configuration options 50 | You can use evniroment variables to change default configurations 51 | ```bash 52 | export IDE_ZEND_PORT=10137 53 | export IDE_XDEBUG_PORT=9000 54 | export IDE_KEY="PHPSTORM" 55 | export IDE_SERVERNAME="$(hostname)" 56 | # SSH client IP will be autodetected by default 57 | export IDE_IP="1.2.3.4" 58 | ``` 59 | -------------------------------------------------------------------------------- /phpdebug.sh: -------------------------------------------------------------------------------- 1 | # Installation steps: 2 | # 1. Put this file under ~/.phpdebug 3 | # $ curl https://gist.githubusercontent.com/torinaki/9059015/raw/.phpdebug > ~/.phpdebug 4 | # 2. Put following lines into ~/.bashrc: 5 | # # Get the aliases and functions 6 | # if [ -f ~/.phpdebug ]; then 7 | # . ~/.phpdebug 8 | # fi 9 | # 3. (optional) Script will try to autodetect your machine IP where runs IDE or use 127.0.0.1 otherwise. 10 | # If automatic detection doesn't work for you, set ip directly via IDE_IP enviroment variable: 11 | # $ export IDE_IP=1.2.3.4 12 | # 4. (optional) Change ports if it not same as default (see local variables zend_debugger_config and xdebug_config); 13 | # $ export IDE_ZEND_PORT=10137 14 | # $ export IDE_ZDEBUG_PORT=9000 15 | # 5. (optional) Change IDE specific configuration: serverName, idekey 16 | # $ export IDE_SERVERNAME="Any_server_name" 17 | # $ export IDE_KEY="PHPSTORM" 18 | # 6. Run: source ~/.bashrc 19 | 20 | # Usage: 21 | # 1. After installation use phpdebug/phpdebugoff commands to start/stop debugging: 22 | # $ phpdebug 23 | # $ php ./script1_to_debug.php 24 | # $ php ./script2_to_debug.php 25 | # $ phpdebugoff 26 | # 2. Or simply use instead of php command to debug only one script 27 | # $ phpdebug -dmemory_limit=1G ./script_to_debug.php 28 | 29 | # Init default evniroment variables 30 | export IDE_ZEND_PORT=10137 31 | export IDE_XDEBUG_PORT=9000 32 | export IDE_KEY="PHPSTORM" 33 | export IDE_SERVERNAME="$(hostname)" 34 | 35 | function _check_xdebug_installed() 36 | { 37 | if ! php -i | egrep -q "(xdebug|zend_debugger)"; then 38 | echo "\e[0;31mWarning! XDebug or Zend Debugger extension not found\e[m" 39 | fi 40 | } 41 | 42 | function _print_settings_info() 43 | { 44 | echo -e "\e[93mXDebug connection is $IDE_IP:$IDE_XDEBUG_PORT and server name '$IDE_SERVERNAME'. Zend Debugger connection is $IDE_IP:$IDE_ZEND_PORT with IDE key '$IDE_KEY'\e[m" 45 | echo -e "\e[93mAny of this settings can be configured with environment variables: IDE_IP, IDE_XDEBUG_PORT, IDE_SERVERNAME, IDE_ZEND_PORT, IDE_KEY\e[m" 46 | } 47 | 48 | function _phpdebug() 49 | { 50 | # For Zend debugger 51 | # Set special EVN variables (don't forget to change "debug_host" and "debug_port") 52 | local zend_debugger_config="start_debug=1&debug_stop=0&debug_fastfile=1&debug_covere=1&use_remote=1&send_sess_end=1&debug_session_id=2000&debug_start_session=1&debug_port=${IDE_ZEND_PORT}" 53 | # For Xdebug 54 | # Set special EVN variables. 55 | # PHPSTORM is default idekey key. It must be same like in PhpStorm -> Settings -> PHP -> Debug -> DBGp Proxy 56 | local xdebug_config="idekey=${IDE_KEY} remote_port=${IDE_XDEBUG_PORT}" 57 | # For PhpStorm 58 | # Same for Xdebug and Zend Debugger 59 | # PhpStorm server config name is placed in Settings -> PHP -> Servers 60 | local php_ide_config="serverName=${IDE_SERVERNAME}" 61 | 62 | # try to autodetect IP if global variable IDE_IP not set 63 | if [ -z ${IDE_IP+x} ]; then 64 | if [ -z "$SSH_CLIENT" ]; then 65 | IDE_IP="127.0.0.1"; 66 | else 67 | IDE_IP=$( echo $SSH_CLIENT | sed s/\ .*$// ); 68 | fi 69 | fi 70 | 71 | zend_debugger_config="${zend_debugger_config}&debug_host=${IDE_IP}" 72 | xdebug_config="${xdebug_config} remote_host=${IDE_IP}" 73 | 74 | _check_xdebug_installed 75 | _print_settings_info 76 | 77 | if [ "$*" = "" ]; then 78 | export QUERY_STRING="$zend_debugger_config" 79 | export XDEBUG_CONFIG="$xdebug_config" 80 | export PHP_IDE_CONFIG="$php_ide_config" 81 | else 82 | PHP_IDE_CONFIG="$php_ide_config" XDEBUG_CONFIG="$xdebug_config" QUERY_STRING="$zend_debugger_config" php $* 83 | fi 84 | } 85 | alias phpdebug="_phpdebug" 86 | alias phpdebugoff="unset QUERY_STRING && unset PHP_IDE_CONFIG && unset XDEBUG_CONFIG" 87 | --------------------------------------------------------------------------------