Debugging PHP over xdebug with Eclipse and Vagrant
This documents the configuration needed to debug FusionForge PHP code under the Eclipse IDE (equipped with the PDT PHP development environment), while executing the code inside the Vagrant-based virtual machine development environment.
This requires :
- sharing the source code between the host and guest
- the activation of the XDebug PHP extension in the VM
Sharing the source code between the host and guest
This is needed so that modifications of the PHP code are instantaneously taken into account in the execution environment.
For this you may for instance add a shared directory in the Vagrantfile, by uncommenting the line :
#config.vm.synced_folder "../src", "/usr/share/gforge"
if you wish to execute the code present in the Git repo from where the vagrant up command is performed
Another option is to perform the following steps before installing the packages built inside the VM (refering to Building and installing FusionForge instructions) :
[... ./build.sh] mkdir /vagrant/usr_share_gforge ln -s /vagrant/usr_share_gforge /usr/share/gforge [... ./install.sh]
This ensures that the PHP code will be extracted in a directory that gets created in the directory where vagrant up was performed on the host
Configuring the PDT environment and VM to use XDebug
Configuring XDebug in the Vagrant VM
Install php5-xdebug in the VM (via vagrant ssh)
sudo aptitude install php5-xdebug
Activate the remote_connect_back option so that Eclipse can pilot XDebug
sudo cat << EOF >> /etc/php5/conf.d/20-xdebug.ini xdebug.remote_enable=1 xdebug.remote_connect_back = 1 EOF
And restart Apache
sudo apache2ctl restart
Verify that XDebug is activated in the phpinfo() at https://forge.internal/admin/pi.php
Configure the Eclipse project to use XDebug
You need to have the Eclipse PDT installed. Attention, the version bundled with Eclipse may not be up to date (for instance the version in the Eclipse Luna distribution at the time of writing has a bug in the refreshing of the current line in case of single step debugging), so you may prefer installing the latest version, from the following software repository :
Then, you need to configure the use of Xdebug for your Web server (you may need to adjust other parameters if you run the VM on custom ports, for instance).
- PHP->Debug->PHP Servers...
- Select "Default PHP Web Server" click on Edit
- Select "Xdebug" from Debugger: choices.
- Click OK
Then set up Eclipse to listen for incoming Xdebug connections
- PHP->Debug->Installed Debuggers
- Select Xdebug click on Configure
- Set "Accept remote session (JIT)" to "prompt"
- Click OK, Click OK
You can now debug the invocation of the forge pages, by stepping through PHP instructions at will.