Following instructions gives you a small HowTo for debugging phTagr code with Netbeans 7.2 and Xdebug on Ubuntu 12.04.
If you like to contribute some code to the phtagr project it is recommended to use a IDE with debugging support. Netbeans IDE is a great and free IDE with a good PHP language support. Combined with the PHP debugger and profiler Xdebug you can execute your code line by line and inspect variables which makes changes and errors easy to handle.
Requirements – Assumptions
- You have some (php) programming skills
- You installed and configured phtagr on your local web server like apache
- You use phtagr source from phtagr’s git repository
Install Netbeans and Xdebug
- Download Netbeans 7.2 for PHP from http://netbeans.org/downloads/index.html
$ chmod 755 netbeans-7.2-ml-php-linux.sh $ ./netbeans-7.2-ml-php-linux.sh
and follow the installation wizard (windows like). For detailed installation instruction visit netbeans.
- Install xdebug via sudo apt-get install php5-xdebug. By default xdebug has a configuration file at /etc/php5/conf.d/xdebug.ini.
- Start netbeans (e.g. run /home/sebastian/netbeans-7.2/bin/netbeans if you installed netbeans in /home/sebastian/netbeans-7.2).
- Create a new project via menu File -> New Project
- Select PHP Application with existing Source. Confirm by clicking Next
- Enter your php git repository (e.g. /var/www/tests/phtagr), the project name. Confirm by clicking Next
- Enter the Project URL. At my machine /var/www is Apache’s web root so http://localhost/tests/phtagr is the correct Project URL. At Index File enter webroot/index.php. Netbeans requires a real file and the main index file of phtagr is in webroot/index.php. Confirm by clicking Next
- Ensure at Menu Tools -> Options -> PHP -> Debugging that Stop at First line is disabled.
- Run Debug Project (shortcut Ctrl+F5). At the first page phtagr will report an error. But this is necessary to set the correct debug cookie for xdebug. Now you can use your phtagr installation and enter Project URL http://localhost/tests/phtagr.
- Use breakpoints to intercept the execution of php script. E.g. set a break point at Controller/AppController.php to function beforeFilter function but clicking on a line number. If you reload the page in your browser by hitting F5, netbeans will stop at your breakpoint line.
- Ctrl+F5 – Start debugger
- F8 – Step Over
- F7 – Step Into
- Ctrl+F7 – Step Out
- F5 – Continue