Skip to content

Instantly share code, notes, and snippets.

@jpcaparas
Last active May 12, 2017 02:54
Show Gist options
  • Save jpcaparas/a0764f204385de5aec27b8ca27d59e9b to your computer and use it in GitHub Desktop.
Save jpcaparas/a0764f204385de5aec27b8ca27d59e9b to your computer and use it in GitHub Desktop.
Enabling PHP 7.0 Xdebug on a Vagrant Debian 8 image
#!/bin/sh
### IMPORTANT: Run this command as sudo ###
### Sample steps ###
# 1. `vagrant ssh` into your machine
# 2. Run `curl http://[raw-url-to-this-script.sh] | sudo sh
### VARS (Change values as needed) ###
XDEBUG_IS_INSTALLED_PATTERN="xdebug.remote_enable=1"
XDEBUG_INI_PATH="/etc/php/7.0/mods-available/xdebug.ini"
XDEBUG_REMOTE_ENABLE="yes" # Xdebug should try to contact a debug client which is listening on the host
XDEBUG_REMOTE_CONNECT_BACK="yes" # Xdebug will try to connect to the client that made the HTTP request
XDEBUG_REMOTE_PORT="9000" # The value is, by default, already 9000, but we're making it explicit
XDEBUG_REMOTE_HOST="10.10.10.10" # Change this to your machine IP
XDEBUG_IDEKEY="vagrant" # Use with the XDebug helper (Chrome extension)
### Install the module ###
apt-get install php7.0-xdebug
### Append configs
if ! grep -q $XDEBUG_IS_INSTALLED_PATTERN $XDEBUG_INI_PATH; then
printf "Configuring Xdebug...\n"
sudo printf "\
xdebug.remote_enable=$XDEBUG_REMOTE_ENABLE\n\
xdebug.remote_connect_back=$XDEBUG_REMOTE_CONNECT_BACK\n\
xdebug.remote_host=$XDEBUG_REMOTE_HOST\n\
xdebug.remote_port=$XDEBUG_REMOTE_PORT\n\
xdebug.idekey=$XDEBUG_IDEKEY\n" >> $XDEBUG_INI_PATH
printf "Configuration done.\n"
else
printf "Xdebug is already configured.\n"
fi
### Restart PHP-FPM ###
systemctl restart php7.0-fpm
### Resources ###
# - PHPSTORM integration: https://www.sitepoint.com/install-xdebug-phpstorm-vagrant/ #
@jpcaparas
Copy link
Author

Instructions for using this snippet:

  1. vagrant ssh into your machine.
  2. Copy contents of the file to install-xdebug.sh and run sh install-xdebug.sh
  3. Run php -v to check if XDebug has been installed.

Gotchas:

  • Use the IDE key vagrant for XDebug to connect back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment