In this post I will show you how to use NetBeans for php development. NetBeans is one of the most popular open source IDE available for web development. It has many advanced features that makes web development an easy task for the developer. Here I will show you some of the most important features of NetBeans that can be used in the web development.
What is an IDE?
An integrated development environment (IDE) is a software application that provides advanced facilities to programmers for software or web development. An IDE usually will have a Graphical User Interface(GUI) builder, a code editor and a debugger. A GUI builder helps programmer to drag and drop elements which will automatically generate the required code for it. A code editor helps programmer to edit the code easily, which will support code auto completion and show the syntax errors to the programmer. The debugger helps programmer to debug the code to check logical errors in the program by running it step by step in the debugger.
NetBeans is an open source IDE which is available for free download from there website at https://netbeans.org/. NetBeans can be used in the development of Java web applications, desktop applications and mobile applications. NetBeans also provide support for the development of C/C++ and PHP. NetBeans can be installed on any operating system that supports Java. NetBeans also can be extended by installing the necessary plugins. It has plenty of plugins available in the NetBeans plugin portal.
NetBeans for PHP development
We can use NetBeans IDE for php development. Here I will use NetBeans with wamp server for running the php. First download and install NetBeans IDE. On opening the IDE you will see the below screen.
Next we will create a new PHP project. Select File->New Project and from the pop-up window select PHP Application.
Now click next button and you will see the below screen.
We can give the Project Name as “sample1”. Now give the Source Folder path as the www root folder of your wamp server. Now click the next button and in the screen check the Project URL is correct.
Then click the next button. In the next screen NetBeans will ask you whether you are using any frameworks in PHP. You can select them if you are using any one in the project. As we are not using any framework in this example we will leave it empty.Then click next button, in the next screen NetBeans will ask you whether you are using Composer to install any packages. We will leave it empty, as we are not using composer in this project.
Then click the finish button to complete the project configuration. Now you will see the below screen.
Now if you click on the run button NetBeans will open the file in web browser. Next we will write a simple loop using php to print numbers from 1 to 10.
<?php // put your code here for($i=1;$i<=10;$i++) echo $i." "; ?>
Now we have to enable xdebug in the wamp server. For that open the php.ini file from the wamp server tray icon menu and paste the below code in the xdebug section which is usually found at the end of the file. You may have to change the paths according to your wamp server installation location.
; XDEBUG Extension zend_extension = "H:/wamp/bin/php/php5.5.12/zend_ext/php_xdebug-2.2.5-5.5-vc11.dll" ; [xdebug] xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 xdebug.remote_autostart=0 xdebug.remote_connect_back=0 xdebug.profiler_enable=0 xdebug.profiler_enable_trigger=0 xdebug.profiler_output_name=cachegrind.out.%s.%t xdebug.profiler_output_dir="H:/wamp/tmp" xdebug.trace_output_dir="H:/wamp/tmp"
Now place the cursor on the echo statement and press Ctrl+F8 to create the break point in the file. After that click the debug project on the top bar to run the debugger in NetBeans. Now you can debug the project by clicking the “Step Over”,”Step Into”,”Step Out” or ”Run to Cursor” buttons on the top. You will be able to see the variable values in the Variables tab in the bottom.