Debugging in Ampps and Netbeans

Please read great article about installation and configuration debugging for PHP in Ampps server.

I just want to add some additional tips before you start downloading and installing files…

Determine you visual C runtime, architecture and thread safety

Open Ampps local control center and check PHP Info page.

2015-09-13 23_17_18-phpinfo()

Files are named with combination of used compiler (MSVC11 = VC11, MSVC9 = VC9), architecture (x86 = 32bit,  x64 = 64bit) and thread safety settings (TS = enabled).

With this information you should select proper DLL for download.

After downloading DLL file for your selected PHP configuration, you must copy file to “php/ext” folder and add  new config setting to php.ini file :

zend_extension="\php_xdebug.dll"

For debuging to work from Netbeans, you need to add this xdebug settings to php.ini file:

xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
; Port number must match debugger port number in 
; NetBeans IDE Tools > Options > PHP
xdebug.remote_handler=dbgp

Restart Apache and check phpInfo() in local ampps web admin page (http://localhost/ampps/).

2015-09-13 23_31_42-phpinfo()After successful installation your breakpoints in PHP code should work as expected.

2015-09-07 21_41_09-NetBeans Platform 8.0.2

When you debug application, link to the application, get additional debug parameter:

http://localhost/webapp03/web/app_dev.php?XDEBUG_SESSION_START=netbeans-xdebug

 

Symfony installer, creating new project

Symfony installer

Symfony is one of the best php frameworks for web development. To start working with symfony we first need to download symfony installer:

c:\> php -r "readfile('http://symfony.com/installer');" > symfony

After downloading symfony file, you can copy it to your new projects folder.

Then you use it with php interpreter as a command:

C:\> php symfony

If you wish to simplify usage of symfony command,  just create dos batch command file (symfony.bat) with next content:

@echo off
call php C:\cmd\symfony %*

Save both files, downloaded symfony file and batch file to a system wide available folder. If you haven’t it yet, create one folder (like C:\cmd) and add it to system environment PATH.  New command “symfony” will then be available anywhere on the system. To check it, open DOS command window and type symfony command:

H:\TEMP> symfony

You should see something like this:

2015-09-04 17_44_31-Command Prompt

Symfony installer installed !

Create first project

To create new symfony project, open DOS command line in projects parent folder and enter command :

C:\ampps\Ampps\www\>symfony new webapp03

As I described in this blog article, my development environment consist of locally installed apache web server. This means I don’t need to start web server every time I want to serve application manually, but AMPPS application must be started of course.

To open newly created application, enter URL of the project into the browser:

http://localhost/webapp03/web/

You will get application default startup page like:

2015-09-06 10_00_35-Welcome! - Opera

Create project in Netbeans with existing source

If you now want to work in Netbeans, just open new project with existing source:

2015-09-07 20_47_23-New Project

 

Select folder where generated project reside and you are good to go. You can create extra meta data folder for netbeans specific project files. This way you will not to pollute  web folder itself.

2015-09-07 20_48_29-New PHP Project with Existing SourcesOn the last step you should define startup file , this could be web/app.php or web/app_dev.php, with some additional development informations from symfony framework in the bottom of the web page.

2015-09-07 20_49_26-New PHP Project with Existing Sources

 

 

PHP development environment on windows

If you are running Windows 7, you will need to install a few things before you can start with development in php.

Web server 

For start, we need some sort of web server to serve PHP web pages.

I select Softaculous Ampps server, because it is simple to install and has tons of open source applications prepared to installation.

Here is  more information about how to install Ampps on windows.

If you already have any other server/service on port 80 (like IIS for example), this will interfere with default configuration of your new Ampps server. The best solution is to stop critical service, reconfigure it to another port or uninstall it, before you install Ampps.

After successful installation, you start server and with little luck, you will see next screen:

2015-09-03 22_09_11-Softaculous AMPPS

Navigate to http://localhost/ampps and you will get administration interface:

2015-09-03 22_42_46-AMPPS - Powered by Softaculous - Opera

PHP and command line support

Just add  php.exe program to PATH environment variable.  PHP is located in C:\ampps\Ampps\php folder inside your server installation directory.

Check php version:

H:\PHP>php -v

2015-09-03 23_43_04-Command Prompt

Composer

Composer is dependency manager for PHP, you will need it for libraries installation later on.  Don’t forget to add composer ComposerSetup\bin folder to the environment PATH, you will use it from command line. Composer is batch file on windows (composer.bat),  so you can run it like a program from command line.

Check composer version:

H:\PHP>composer -v

2015-09-03 23_41_27-Command Prompt

 

Netbeans IDE

There is a lot of choice in selection of best PHP IDE. If you looking for decent intellisense support, good debugging support and you want it for free,  Netbeans is one of the best out there.

Just install “HTML5 & PHP only” edition, you will get smaller and faster IDE.  After installation, try to  deactivate plugins you are not using, to speed up startup time even more.

Create first project

Open Netbeans IDE add new project (File/New project) :

2015-09-04 00_13_39-New Project

Put your new project directly to local web server folder (C:\ampps\Ampps\www\project_folder) and put netbeans specific metadata (project management) files to separate directory. This way, your code in web server, will stay clean and ready to upload to hosting server.

2015-09-04 00_15_20-New PHP Project

In this step, you select deployment method. Actually, there is no deployment at all, we run project directly from local web server.

2015-09-04 00_15_35-New PHP ProjectOther options are not required , so we finish  project creation procedure.

2015-09-04 00_18_12-NetBeans Platform 8.0.2

Put some code inside php tag in index.php file, for example something like that:

<?php
echo 'Web sample 01'; 
?>

Now you run application, from Netbeans with  run command or navigate to application URL address in browser.

http://localhost/webapp01/index.php

And result of this first simple application in browser is :

2015-09-04 00_35_38-localhost_webapp01_index.php - Opera

Netbeans plugins – QuickOpener

The most important feature for me is ability to open OS shell (DOS command window) on the location of the selected file. Select a file in project tree inside netbeans and  hit Alt+1.

2015-09-07 22_58_41-C__Windows_system32_cmd.exeNot to rely too much on IDE is important to me. Many features in web development require command line interface and easy access to command line, directly from the project tree, is very important.