Debugging PHP-App Hosted in VirturalBox CentOS VM Using Netbeans

Debugging PHP-App Hosted in VirturalBox CentOS VM Using Netbeans

Setting up debugging locally on one machine (both Netbeans and xdebug on the same host) is easy enough. However, if you want to connect Netbeans to a xdebug over to a guest virtual machine, it will require a bit of work, but not hard. My host machine is Windows 7 and running a CentOS virtual machine inside VirtualBox. The following was what I did to get it running. Firstly I installed C and C++ compilers, which comes in the “Development Tools”
$ sudo yum groupinstall 'Development Tools'
then I installed php-devel which would give me phpize (which is required by pecl when installing xdebug)
$ sudo yum install php-devel
Now I was ready to install xdebug:
$ sudo pecl install xdebug
Once that was done, I updated php.ini file to enable xdebug. Find the xdebug section in php.ini file, if no, create one section for it under /etc/php.ini
[debug]

zend_extension=/usr/lib64/php/modules/xdebug.so

xdebug.remote_enable  = On
xdebug.remote_host    = 10.0.2.15
xdebug.remote_port    = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode    = req

xdebug.remote_connect_back = On
xdebug.idekey = "netbeans-xdebug"
xdebug.remote_log = /tmp/xdebug.log
You will need to find the path to xdebug.so file by running:
find / -name xdebug.so
Yours might be different from mine. Now I was ready to enable xdebug in Netbeans, which was running on the host machine (Windows 7 in my case). Under Tools > Options > PHP > Debugging:
Debugger Port: 9000
Session ID: netbeans-xdebug
Under Project Properties (right click on project root in the Project window) > Run Configuration: Run as: Local Web Site (running on local web server) Project URL: http://localhost:8080/ Index file: index.php (I have setup port forwarding from 8080 on my localhost to port 80 on my virtual machine) Under Project Properties > Run Configuration > Advanced Debug URL: Default: http://localhost:8080/index.php Path Mapping: Server Path: /path/to/project/in/guest Project Path: /path/to/project/in/host/ That’s it, now I am able to start setting break points and press Ctrl + F5 to start debugging in Netbeans over the virtual machine.

Leave a Reply

Your email address will not be published. Required fields are marked *

My new Snowflake Blog is now live. I will not be updating this blog anymore but will continue with new contents in the Snowflake world!