Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save RazaChohan/51bffc660d52eae8a75dd0f9503740bf to your computer and use it in GitHub Desktop.
Save RazaChohan/51bffc660d52eae8a75dd0f9503740bf to your computer and use it in GitHub Desktop.
Walkthrough for installing xdebug for php 7 on linux and enabling its support for phpstorm.

Xdebug Installation

Please follow the following steps to configure Xdebug on Linux.


Tested on

  • Linux mint 17.1 Rebecca

  • PHP 7.0 (Installed using PPA by Ondrej)

  • LAMP installed using Tasksel

  • PHPStorm 2016.2

Pre Requisites

This installation assumes you have following installed.

  • Apache2

  • PHP 7.0

  • PHPStorm (If Xdebug support is required, else not necessary)

Steps

  • Open terminal and write following command

php -i > /var/www/html/php_info.txt

  • Copy the output from /var/www/html/php_info.txt

  • Go to Xdebug.org , and paste the output inside the text box on the page. It will analyze the output and will recommend the most suited package of Xdebug.

  • Download it.

  • Go to the folder where you downloaded the tar file and run the following command there.

    tar -xvzf XDEBUG_FILE_YOU_DOWNLOADED.tgz

  • Now go inside the directory where tar extracted the contents of XDEBUG_FILE_YOU_DOWNLOADED.tgz file.

  • Before doing anything else run

    sudo apt-get install php7.0-dev

    if you already have the php dev package installed skip this point.

  • Run following sequence of commands to build the Xdebug extension from its source.

    phpize

    ./configure

    make

  • Up until this point if you get no errors, you will have a folder named modules in your current directory.

  • Run following command to place the freshly created Xdebug extension inside the php folder.

    sudo cp modules/xdebug.so /usr/lib/php/20151012/

  • Now go to /etc/php/7.0/mods-available, and create following file.

    sudo touch xdebug.ini

  • Open the xdebug.ini file in your favorite editor, and add following lines to it.

    zend_extension=/usr/lib/php/20151012/xdebug.so
    xdebug.remote_enable=1
    xdebug.remote_port=9000
    xdebug.profiler_enable=1
    xdebug.profiler_output_dir=PATH_TO_PROFILER_OUTPUT_DIR
    xdebug.remote_log=PATH_TO_LOG/xdebug.log

    change the PATH_TO_PROFILER_OUTPUT_DIR to point to the directory you want to receive profiler output. change PATH_TO_LOG to point to the directory where you want to receive xdebug.log

  • Create symlink to the xdebug.ini using following command.

    sudo ln -s /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini

  • Now run the following commands.

    sudo phpenmod xdebug

    sudo service apache2 restart

At this point you will have Xdebug installed and configured to use, you can use

php -v

to check if xdebug is installed or not.

Configuring Xdebug for PHPStorm

  • Open your project in PHPStorm

  • Go to File > Settings > Languages & Frameworks > PHP.

  • Select Language level to PHP 7 and choose interpreter to PHP 7 as well.

  • Click on the menu icon next to Choose interpreter option and set PHP executable path to /usr/bin/php and Debugger extension to /usr/lib/php/20151012/xdebug.so

  • Click Ok to apply the changes.

  • Now to check if PHPStorm is able to access Xdebug, click on Run > Start Listening for PHP Debug Connections option at the end, Then open Run > Webserver Debug Validation panel. Click on validate and it should show you the currently loaded xdebug extension version inside information pane.

  • Now set breakpoint inside the app and then start run the app in debug mode and phpstorm should pause the execution at the set breakpoint.

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