How to install xdebug for lsphp

I was reviewing setting up xdebug for phpstorm recently and stumbled on some posts which while helpful were not entirely complete.

https://xdebug.org/docs/install#pecl

Installation via pecl is easiest so first step is ensuring pecl is updated.

Update pecl

for version in $(ls /usr/local/lsws|grep lsphp); do /usr/local/lsws/${version}/bin/pecl channel-update pecl.php.net; done

Install via pecl for Centos

Extension=“xdebug”;for version in $(ls /usr/local/lsws|grep lsphp); do php_ini="/usr/local/lsws/${version}/etc/php.d/zzzzzzz-pecl.ini"; printf ’
’ |/usr/local/lsws/${version}/bin/pecl install ${Extension} && echo “zend_extension=${Extension}.so” >> ${php_ini}; echo “xdebug.mode=debug” >> ${php_ini}; echo “xdebug.remote_enable=1” >> ${php_ini}; echo “xdebug.remote_connect_back=1” >> ${php_ini}; echo “xdebug.remote_port=9000” >> ${php_ini}; echo “xdebug.client_port=9000” >> ${php_ini}; done; systemctl restart lsws||service lsws restart; systemctl status lsws||service lsws status;

Install via pecl Ubuntu

Extension=“xdebug”;for phpver in $(ls -1 /usr/local/lsws/ |grep lsphp | sed ‘s/lsphp//g’); do php_ini="/usr/local/lsws/lsphp${phpver}/etc/php/$(echo $phpver | sed ‘s/^\(.\{1\}\)/\1./’)/litespeed/php.ini"; printf ’
’ |/usr/local/lsws/lsphp${phpver}/bin/pecl install ${Extension} && echo “zend_extension=${Extension}.so” >> ${php_ini}; echo “xdebug.mode=debug” >> ${php_ini}; echo “xdebug.remote_enable=1” >> ${php_ini}; echo “xdebug.remote_connect_back=1” >> ${php_ini}; echo “xdebug.remote_port=9000” >> ${php_ini}; echo “xdebug.client_port=9000” >> ${php_ini}; done; systemctl restart lsws||service lsws restart; systemctl status lsws||service lsws status;

Should look like this
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.client_port=9000
xdebug.client_host=YOURIP

Check if its installed

for version in $(ls /usr/local/lsws|grep lsphp); do echo “”; echo “PHP $version”; /usr/local/lsws/${version}/bin/php -v; done

Example:

[root@wcloud:~]# for version in $(ls /usr/local/lsws|grep lsphp); do echo “”; echo “PHP $version”; /usr/local/lsws/${version}/bin/php -v; done

PHP lsphp70
PHP 7.0.33 (cli) (built: Nov 22 2019 11:16:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.3.9, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend OPcache v7.0.33, Copyright (c) 1999-2017, by Zend Technologies

PHP lsphp71
PHP 7.1.33 (cli) (built: Nov 22 2019 11:40:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.3.9, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies

PHP lsphp72
PHP 7.2.34 (cli) (built: Oct 1 2020 17:07:20) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.3.9, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans

PHP lsphp73
PHP 7.3.26 (cli) (built: Jan 7 2021 09:22:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.26, Copyright (c) 1998-2018 Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.3.9, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend OPcache v7.3.26, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans

PHP lsphp74
PHP 7.4.14 (cli) (built: Jan 7 2021 08:53:32) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.4.4, Copyright (c) 2002-2020, by ionCube Ltd.
with Zend OPcache v7.4.14, Copyright (c), by Zend Technologies
with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans

PHP lsphp80
-bash: /usr/local/lsws/lsphp80/bin/php: No such file or directory
[root@wcloud:~]#

Hopefully this is helpful for anyone else looking to setup their IDE and remote debugging.

@whattheserver Thanks very much for this! I didn’t realize that xdebug could be set up so easily with PECL and did it manually from source.

I have php 7.4 set as the default and got it configured, but I can’t figure out how to install for 7.3. Can you please provide a bit more clarity on how to do this?

Nevermind, I figured out the source method with the help of this article! How to setup xdebug to work with manually compiled php 5.2.17 on ubuntu (arashmilani.com)

Here are instructions updated for installing xdebug on PHP 7.3 (I already did 7.4, which is the default php version for my system).

  1. Create a file named info.php in the root of the site that is using the php version you want to install xdebug for. e.g. /home/domain.com/public_html/info.php

add this code to it

<?php

phpinfo( );

?>
  1. Navigate browser to domain.com/info.php
  2. Copy the entire page and paste it into the textbox at this Xdebug install wizard. Click the Analyse button and follow the first few steps on that page.
  3. In your server’s ssh root, use wget to download the xdebug source file. e.g. wget https://xdebug.org/files/xdebug-3.1.3.tgz
  4. Unpack the file tar -xvzf xdebug-3.1.3.tgz
  5. Run cd xdebug-3.1.3
  6. If this site is using your system’s default php version, continue with the instructions on that page. They will work. If it is for an alternative version of php, continue with these instructions.
  7. The key concept here is to use the correct version of “phpize”. to find the “phpize” for your php 7.3 just run this command: sudo find / -name "phpize".
    In my case it was at /usr/local/lsws/lsphp73/bin/phpize
  8. Run sudo /usr/local/lsws/lsphp73/bin/phpize
    You should get this output. If you see other numbers for API versions it means the “phpize” is not for php 7.3
Configuring for:
...
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
  1. Now we need to find the configuration file location for php 7.3. sudo find / -name "php-config"
    Mine was at /usr/local/lsws/lsphp73/bin/php-config

  2. Run sudo ./configure --enable-xdebug --with-php-config=/usr/local/lsws/lsphp73/bin/php-config

  3. Run sudo make

  4. Run cp modules/xdebug.so /usr/local/lsws/lsphp73/lib/php/20180731

  5. Run nano /usr/local/lsws/lsphp73/etc/php/7.3/mods-available/99-xdebug.ini and add zend_extension = "/usr/local/lsws/lsphp73/lib/php/20180731/xdebug.so" to the file, add other config parameters such as

xdebug.mode = debug, develop
xdebug.start_with_request = trigger
xdebug.client_port = 9003
xdebug.connect_timeout_ms = 200
xdebug.idekey = VSCODE
xdebug.trigger_value = [enter the passkey you want to use in your browser xdebug extension]

Then press Ctrl+O to save and Ctrl+X to exit.

  1. Restart the web server.
  2. Navigate to domain.com/info.php and you should see something like this

If you don’t, try clearing the browser cache.