Ad

Xdebug In Vagrant Laravel/homestead V0.4.0 / V3.0.1

- 1 answer

I set up a vagrant box laravel/homestead v0.4.0.
I install homestead V3.0.1 using composer.
Finally I run "vagrant up" and then "vagrant ssh" and i am inside the Homestead VM, but...

It supposed to include Xdebug, but it hasn't...
When I run phpinfo() there is no Xdebug info.
Also in /etc/php/7.0/fpm/php.ini or in the config.d folder, there is no configurations for Xdebug.

My final goal is to be able to debug a laravel project with Netbeans IDE. The project is running inside the homestead VM, but im stuck understanding why there is not Xdebug in the homestead virtual machine. Any help to achive this is highly appreciated

Ad

Answer

EDIT: As of version 0.4.1, XDebug was put back into Homestead. Compiling XDebug from source should no longer be necessary.


In your ~/.homestead directory, there should be a file called after.sh. This will provide you a means by which you can execute your own commands after the Homestead provisioner has finished.

Copy and paste the following into your after.sh file:

#!/bin/sh

# Install Xdebug
git clone git://github.com/xdebug/xdebug.git
cd xdebug
phpize
./configure --enable-xdebug
make
make install

# Configure Xdebug
cat > /etc/php/mods-available/xdebug.ini <<EOL
zend_extension=xdebug.so
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
EOL
ln -s /etc/php/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini
service php7.0-fpm restart

Once complete, run a vagrant destroy and a vagrant up, or run vagrant provision to ensure the shell command executes properly.

This version of XDebug is a direct clone of the Github Master branch. This branch is considered unstable. Once the Xdebug github account adds a branch for either 2.4 or 2.5, make sure to update your shell command to checkout that branch before running the various configuration and make commands.

Additionally, I'm only adding Xdebug to the FPM configuration. I am not adding it to the CLI configuration. You will likely see Xdebug only in a phpinfo() call, and not a php -i call.

Aside from that, I tested this on my own environment:

  • Homestead box version 0.4
  • Github clone laravel/homestead 3.0.1
  • PHPStorm IDE

Everything seems to work as expected. Let me know if this helps.

Ad
source: stackoverflow.com
Ad