Ubuntu 12 - Setting Up PHP Xdebug (with mod_rewrite)

Introduction

This tutorial assumes that you have already installed and set up a normal LAMP service (tasksel) on your Ubuntu 12.04 desktop and have installed the latest version of Netbeans. For this tutorial, I am using netbeans version 7.3.1.

    Run the following commands:
    sudo apt-get install php5-dev php-pear
    sudo pecl install xdebug
    We need to find where xdebug.so was set up
    sudo find / | grep xdebug.so
    Copy the path that it outputs
    Edit the php ini file
    sudo gedit /etc/php5/apache2/php.ini
    Add the following lines
    zend_extension="(COPIED-PATH-GOES-HERE)"
    xdebug.remote_enable=On
    xdebug.remote_host=localhost
    xdebug.remote_port=9000
    xdebug.remote_handler=dbgp
    Restart the Apache service.
    sudo service apache2 restart
    Optional: check that xdebug has been set up correctly by changing your index.php file to:
    <?php
    echo phpinfo();
    
    Then navigate to localhost and you should see some text showing: "with Xdebug" towards the bottom as shown here:
    Add the xdebug helper to chrome from the 'store' (just type xdeub into the search). There should be an addon that looks like this:
    Note: I did try to get this to work with firefox and the 'easy xdebug 1.5 addon' but couldn't get it to work so for now I'm using chrome.
    Right click the grey xdebugger icon on the right hand side of the URI bar, and select 'options' from the dropdown.
    Select 'Netbeans' from the dropdown menu and close that menu and chrome.
    Change your netbeans debug configuration to not open a browser by right clicking your project before clicking properties. Then click 'run configuration' (1) which is below 'sources' in the left pane before clicking 'Advanced' (2) in the right pane and then selecting bottom radio button (3).
    Double check the 'sources' configuration you went past in the previous step, and make sure all the settings in there are correct. E.g. you have specified public_html as your document root if you have such a folder.
    Restart netbeans (don't ask me why, but turning it off and on again was the only way I could get this to work, typical).
    Place a breakpoint on a line of your code, preferably somewhere that is guaranteed to be run when you load your site.
    Press cntrl-f5 to start debugging in neteans. A message should appear in the bottom right stating: 'Waiting for connection'.
    Open chrome and navigate to your site.
    Click the bug in the URI bar so that it is green to indicate that it is on.
    Netbeans should now have 'connected' after having activated the chrome xdebugger. If you navigate around your site, eventually your breakpoint should trigger and the pay will have 'stopped'. This shows that it is all working.

Sources/References

No comments:

Post a Comment