Linux Powered By Azure – NetBeans Debugging

Now that we got NetBeans communicating with the remote server, we need to configure the remote server to enable debugging.

Prerequisites

We need to SSH to our remote machine. I am not going to go over that since that was covered in the setting up the Linux VM tutorial.

Once you SSH into the remote machine we need to install PHPs remote debugger. Enter the following command:

  • sudo apt-get install php5-xdebug

Once installed it now needs to be configured to allow remote debugging.

  • sudo vi /etc/php5/mods-available/xdebug.ini

Add the following lines to to bottom of the file

  • # Added for xdebug
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000

Then restart the Apache server

  • sudo service apache2 restart

Remember in the second part of the tutorial we created an info.php file? Well browse to that in your web browser and search for xdebug_remote_enable and you will see it is on.

Now lets go into Azure control panel and open an endpoint.

Go to your VM and choose Endpoint.

endpoint-step-1

Choose “Add”

endpoint-step-2

Choose Add a Stand Alone Endpoint

endpoint-step-3

Now there is no XDEBUG in the dropdown menu so I just added it and the port numbers of 9000.

We are almost done. Now we need to create an SSH tunnel to send traffic through the server back to your connected machine. Remember in the step above where we were editing the xdebug.ini file and remote host was localhost? We could put our IP address but then we would have to open a port on our router etc. Since we set up SSH in the prior tutorials this way is jsut as easy.

To create a tunnel issue the following command on your local computer

  • ssh -R 9000:localhost:9000 -i /.ssh/YOURKEYNAME.key YOURUSERNAME@YOURDNSNAME.cloudapp.net

Let that run in the background.

Open up your project in NetBeans and perform the following:

  • Right-Click on the project -> File -> New PHP File
  • Add the following to the file:
    • $X = 5;
      $X = 8;
      $Y = 2;
      $Z = $X + $Y;
      $Z = $Z + 1;
      echo “Z value is: ” . $Z;

Really can be anything. File save it and it will get sent back up to the server.

Make sure you have a breakpoint somewhere in that file.

Then Right Click on the file and choose Debug and watch.

debug-step-1

Be sure to check out the other Linux Tutorials!

Leave a Comment

(0 Comments)

Your email address will not be published. Required fields are marked *