|"If debugging is the process of removing bugs, then programming must be the process of putting them in..."|
Debuggen von PHP Skripten mit Quanta Plus und Gubed PHP Debugger [german version]
about this tutorial
This tutorial assumes that you are a web developer who creates dynamic webpages with the PHP scripting language. It is further assumed that your operating system of choice is Linux/Unix-based and your preferred IDE is Quanta Plus. You will learn how you can use the Gubed PHP Debugger in combination with Quanta Plus to hunt down the bugs in your PHP scripts. (send feedback to: office[at]very-clever.com)
The screenshots and instructions are based on Quanta Plus version 3.4.0 and Gubed PHP Debugger version 0.1.4
Click on images for for larger versions.
some usefull books
Linux, Apache, MySQL,
PostgreSQL, SQL, PHP,
HTML, CSS, Open Source,
Step 1: Make sure Apache and PHP are up and running (on your local machine)
I recommend to use XAMPP
"Many people know from their own experience that it's not easy to install an Apache webserver and it gets harder if you want to add MySQL, PHP and Perl.
XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use - just download, extract and start."
(quoted from the homepage of XAMPP)
Step 2: Make sure Quanta Plus is ready for use
Step 3: Installation and configuration of Gubed PHP Debugger
a) download the latest version of Gubed
Attention: You need to download the "Gubed Quanta" package.
e.g. GubedQuanta3_4.tar.gz depending on your version of Quanta Plus
b) extract the gzipped tar archive
The archive contains the directory "docs" and one named "Gubed".
After finishing this tutorial you should read the files inside the "docs" directory to learn more about Gubed (e.g. How to use Gubed without Quanta Plus).
c) Let's assume that your HTTP Server (e.g. Apache) is configured (DocumentRoot directive) to serve files from /opt/lampp/htdocs - this is the default setting if you use XAMPP.
Copy the "Gubed" directory to your web-directory (/opt/lampp/htdocs/Gubed)
d) Create a file called 'localsettings.php' within the Gubed directory that contains:
$gbdDebugServer = "localhost"; // tells the webserver where to find the debug-server
$gbdDebugPort = 8016; // port to connect to the debug-server
The debug-server is built into Quanta Plus. When you debug a PHP script your webserver needs to connect to the debug-server. The variable $gbdDebugServer specifies the hostname or IP address of the host on which your debug-server is running. The webserver tries to communicate with this host.
In this tutorial the webserver runs on your local machine and thus can connect to the debug-server via 'localhost' or 127.0.0.1
If you wanted to debug a script on your remote production server you would have to copy the 'Gubed' directory to the remote host and set $gbdDebugServer to your local computer's IP address and make sure that the port specified with $gbdDebugPort is open for connections.
Step 4: Create a new project in Quanta Plus
a) Create a new directory 'test' in your webservers document root (/opt/lampp/htdocs/test)
b) Create a new project in Quanta Plus (menu: Project - New Project...)
c) Set the project name to 'test project' and the main directory to '/opt/lampp/htdocs/test'
d) Click 'Next >' two times
e) Click 'Finish'
Step 5: Start the debug-server for your current project
a) Open the projects properties window (menu: Project - Project Properties)
b) Change 'Debugger: No Debugger' to 'Debugger: Gubed'
Notice how the 'Options' button at the right of the selection box gets enabled by this step. Here you can change some advanced options of the debugger.
c) Click 'OK'
Notice that by enabling the debug-server Quanta Plus offers some new features in its user interface:
1) debugger menu: this allows you to controll the debugger functionality
2) debugger toolbar: provides shortcuts to the most important commands
3) variables toolview: shows the contents of the watched variables
4) breakpoints toolview: lists your breakpoints
5) debug Output toolview: shows the output of the debugger
Step 6: Debugging
a) Create a new PHP script or load an existing one.
e.g. script 'example.php' saved in '/opt/lampp/htdocs/test'
b) Open 'http://localhost/Gubed' in your webbrowser.
c) Click on the link 'StartSession'
d) Enter the path of the script you wish to debug
e) Click 'Debug'
f) Change back to Quanta Plus
g) Use the debugger menu or debugger toolbar to debug your script
To watch a variable you can either use the menu (Debug - Variables - Watch Variable) or you can highlight a variable in the source code a use the context menu.
While debugging you can see the value, type and size of your watched variables in the variables toolview.
the debugger toolbar
|Executes the script showing every line of execution to the user (slow). If a script is currently not being debugged, the next script started will start in run mode.|
|Executes the script without showing every line of execution to the user (fast). If a script is currently not being debugged, the next script started will start in leap mode.|
|Executes the next line of execution, but does not step into functions or includes.|
|Executes the next line of execution and steps into it if it is a function call or inclusion of a file.|
|Executes the rest of the commands in the current function/file and pauses when it is done (when it reaches a higher level in the backtrace)|
|Skips the next command of execution and makes the next command the current one.|
If you want to debug your script again when finished, simply reload the current page of your webbrowser to start a new debugging session.
PHP-scripts debuggen met Quanta Plus [dutch version of this tutorial by Fabrice Mous]