Jump to content

How to use Xdebug to debug WHMCS modules


Vasily

Recommended Posts

Hello,
I glad to share my way to debug code for WHMCS modules

WHMCS uses IonCube Loader, so there is a lot of difficulties to use Xdebug and IonCube Loader together.

The basic idea is to run the debug connection on demand in order to skip the encoded code.

Install Xdebug

yum -y install gcc gcc-c++ autoconf automake make php56-devel php56-pear
pecl install Xdebug-2.5.5
 

Configure Xdebug

cat > /etc/php.d/xdebug.ini <<FILE
;[xdebug]
zend_extension="/usr/lib64/php/modules/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.idekey=PHPSTORM
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_connect_back=1
xdebug.remote_port=9000
FILE
 

Restart your httpd server and make sure Xdebug is loaded after IonCube

[root@whmcs ~]# php -v
PHP 5.6.40 (cli) (built: Jan 12 2019 13:11:15)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.3.2, Copyright (c) 2002-2018, by ionCube Ltd.
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
[root@whmcs~]#
 

Configure the server in PHPStorm

image.thumb.png.a95019b0399c2de3a57b01728f0163f2.png

image.thumb.png.779db97281600a704bed21aa29a334c1.png

Start the debug session 

Start listening for PHP Debug Connections

Add the following code to your file/class/method to interrupt executing and start the debug session 

ini_set('xdebug.remote_mode', 'jit');
try {throw new \Exception();} catch (\Exception $e) {
    $breakpoint = 1;
}

image.thumb.png.2f8e2678c5d0393b7309aa6f848ab7e7.png

Edited by WHMCS ChrisD
Added in a code to code box
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated