FreeBSD Programming Primer – Part 11

}

December 31, 2013

In the penultimate part of our series on programming, we will look at using the Netbeans Integrated Development Environment to debug and edit our CMS.


Unfortunately, the Internet gremlins have got me at the moment so this how-to is going to be very short. My local telco is currently rolling out fibre in the area, and my ADSL internet connection is very unreliable, but hopefully I will be able to wrap up the programming primer in part 12 with a bumper edition.

While debugging at the command line using echo statements or commenting out code is possible, a more frequent scenario is that our project will be residing on a remote server and we will need to see the actual processes in action. Often developers will have a local copy of the LAMP stack on their PC or laptop, so that they can debug locally. However, what happens when our development environment is on a laptop and the code is on a remote server? A frequent approach is to use an Integrated Development Environment (IDE) with a built in file transfer utility. Coupled with Xdebug, which supports PHP, we can download our remote code and debug (step through) each line, examine variables etc. To do this, we will need to install Xdebug on our server and install the IDE of our choice on an available local PC. This can be FreeBSD, Windows or Linux, but in my case I was using an Ubuntu desktop. The IDE installation will vary from environment to environment, full details can be found at https://netbeans.org. The IP address of of my desktop PC for this exercise was 192.168.0.123.

Installing Xdebug

Rather than using the FreeBSD provided software, I downloaded the latest version from http://xdebug.org. The reason for this is that in the past I have had problems getting the standard packaged version of Xdebug working with certain distro’s, where as the latest Xdebug and latest Netbeans IDE always seem to work OK together.  Once you have downloaded the latest version of the tarball (Currently xdebug-2.2.3.tgz) into your home directory, on the remote server (192.168.0.118) as root, perform the following (Listing 1).

Add the following to /user/local/etc/php/xdebug.ini (Listing 2). Replace 192.168.0.123 with the IP address of your client machine.  Restart Apache (Listing 3).

If we now login as admin and visit our PHPinfo page at http:/192.168.0.118/phpinfo.php, we should see that Xde-bug is installed and running (Figure 1). If you have not already done so, download and install Netbeans on a local PC of your choice. You will need a working Java installation and Firefox installed for this to work.

Figure 1. PHP Xdebug installed
Now follow the Figures (Figure 2 – 10). If all goes to plan, you should be able to step through your code by pressing F7, and interrogate variables by hovering over them e.g. $request. While debugging, the breakpoint line should change colour from pink to green. If it does not, there is some mis-communication between Netbeans and the server. See xdebug.log for further details.

Figure 2. Create a new project with PHP application on remote server

Figure 3. Give the project a name

Figure 4. Create a new remote connection by clicking on Manage bug is installed and running (Figure 1). If you have not already done so, download and install Netbeans on a local PC of your choice. You will need a working Java installation and Firefox installed for this to work.

Figure 5. Create a new SFTP connection (SSH must be running on Port 22 of your server)

Figure 6. Testing the connection

Figure 7. A successful connection

Figure 8. The final settings of the remote project. Replace with your server IP address as required

Figure 9. Download the source tree – disable Adminer and sqlbuddy

Figure 10. Load Index.php click on line 52 and start the debug session by pressing Ctrl F5


About the Author:
Rob Somerville has been passionate about technology since his early teens. A keen advocate of open systems since the mid-eighties, he has worked in many corporate sectors including finance, automotive, airlines, government and media in a variety of roles from technical support, system administrator, developer, systems integrator and IT manager. He has moved on from CP/M and nixie tubes but keeps a soldering iron handy just in case.

Join iX Newsletter

iXsystems values privacy for all visitors. Learn more about how we use cookies and how you can control them by reading our Privacy Policy.
π