Open SourceThe NetBeans IDE for PHP Development

The NetBeans IDE for PHP Development

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

For millions of developers around the globe, the NetBeans IDE is their code editor of choice. An open source project fostered by Sun Microsystems (now Oracle) for more than a decade, NetBeans has grown from a Java-specific solution to a powerful development ecosystem supporting multiple languages and hundreds of extensions (known as plugins to the NetBeans community). Although support for PHP didn’t come until the 6.5 release (November 2008), it’s already fast becoming one of the PHP community’s most popular IDE choices.

In this article I’ll introduce the NetBeans IDE from a PHP developer’s perspective, highlighting the key features that can make you a more productive PHP developer.

Installing the NetBeans IDE

You can easily install the NetBeans IDE using a platform-specific installer found at NetBeans.org, so point your browser there and click the Download button on the home page. Next, you’ll be prompted to choose from several available downloads, as NetBeans supports multiple languages, including C, C++, Java (FX, ME, and others), PHP and Ruby. You can choose the PHP-specific bundle, or select the All option to download the version that bundles universal support for all languages.

Incidentally, for you Ubuntu users like me, as of this article’s publication date version 6.8 is not available via Ubuntu’s repositories. Instead, you’ll also need to download the Linux installer from the NetBeans Website. All you need to do is set execute permissions on the downloaded file, and run it from the command line to begin the installation process.

When complete, fire up the newly installed IDE to begin exploring its PHP capabilities!

Creating a PHP Project

To create a new PHP project, navigate to File -> New Project and choose PHP Application from the list of options. If you’re already working on a PHP project and would like to continue doing so in NetBeans, choose the PHP Application with Existing Sources button. In either case, click Next to proceed.

Presuming you’re creating a new PHP project, next you’ll be prompted to name your project (see Figure 1 below), select a storage location (which presumably will reside within your Web server’s document path), and identify the PHP version you’ll be using in conjunction with this project (this decision affects only adjustments made by the NetBeans IDE to account for version-specific syntax changes).

Configuring a PHP Project in NetBeans
Figure 1. Configuring a PHP Project in NetBeans:
When creating a new PHP project, you’ll be prompted for the necessary information.

Finally, if you require an encoding format other than UTF-8, you can change the default here. When you have made the choices, click the Next button to continue configuring your project.

Next, you’ll be prompted to specify whether this project will run locally or remotely. Although I’ll presume you’re going to run the project on a local Web server, note that you also can configure the NetBeans IDE to upload files to a remote server using FTP or SFTP by setting the project to run remotely. On this screen you’ll also define the project URL, which if you’re running locally will depend upon how you have configured Apache to access the project’s home directory. When the choices have been made, click the Next button to continue configuring your project.

On the final screen you’ll be prompted to confirm whether your project will use a PHP framework. Currently only the Symfony framework is listed, but I imagine we’ll soon see other frameworks supported here. Keep in mind that even if your favorite framework does not appear here you still can use NetBeans in conjunction with other framework solutions! The upcoming section “Integrating NetBeans and Your Favorite PHP Framework” provides more information about this matter. In the meantime, click the Finish button to create your new project.

Code Completion

PHP offers thousands of native functions, so remembering the spelling and input parameters of even the ones you commonly use can be a real chore. Therefore, perhaps the nicest fundamental PHP feature is the code completion (see Figure 4 for an example), which uses autosense to produce a list of available function candidates based on the function name you’ve started to type. You can scroll through this list, reviewing the required parameters and definition of each. A link to the manual page is also provided, although later in this article I’ll show you a much more convenient way to retrieve a PHP function’s manual page.

Class Browsing

As your projects grow in size, you can easily lose track of the location of a particular method. Using NetBeans’ class browser, you can navigate to the specific location of a class or method definition simply by clicking on its name, as depictured in Figure 2.

Browsing a PHP Class
Figure 2. Browsing a PHP Class:
You can navigate to the specific location of a class or method definition.

Using filters located at the bottom of the class browser, you can filter this listing to show only class fields, class methods, or non-public methods.

Integrating NetBeans and Your Favorite PHP Framework

NetBeans 6.8 includes native support for the Symfony Framework (see this blog entry for a breakdown of available features), enabling features such as Symfony-specific code completion, the ability to navigate among project views and actions, and other useful features. Hopefully we’ll see support for other frameworks such as the Zend Framework in the near future. In the meantime, you can easily add code completion for your favorite framework. To do so, right-click on your project’s name within the Projects window and click on the Properties option. Click the PHP Include Path entry and then click the Add Folder… button (see Figure 3) to add your framework’s library to the project’s source inclusion path.

Adding a Path to Your Project's Source Inclusion Path
Figure 3. Adding a Path to Your Project’s Source Inclusion Path:
You can easily add code completion for your favorite framework.

In Figure 3 you can see I’ve added a path to the Zend Framework’s library directory. When added, you’ll have the convenience of code completion when using Zend Framework components, as depicted in Figure 4.

Using Zend Framework Code Completion
Figure 4. Using Zend Framework Code Completion:
Just add a path to the Zend Framework’s library directory.

PHP Manual Navigation

If I had a dollar for every time I’ve had to visit PHP’s date() function manual package, this article would have been submitted from a remote island in the Caribbean. To ease the time required to look up various functions within the PHP manual, you can install the PHP Manual Search plugin. This plugin automatically opens the proper manual page in your browser when you place the cursor within a function name in your script and click on the PHP logo on your toolbar. To install the plugin, navigate to Tools -> Plugins, and click on the Available Plugins tab. Search through the list until you find the PHP Manual Search listing, and click the Install button to install it.

MySQL Integration

Although not directly related to PHP, MySQL is such a commonplace database solution for PHP developers that it seems beneficial to mention NetBeans’ useful native support for managing your MySQL databases. Although I typically use the command-line mysql client, phpMyAdmin, or SQLYog for managing and navigating my MySQL databases, NetBeans’ native feature nonetheless offers a useful interface when you need to confirm the name of a particular column or table quickly.

To enter your MySQL server from NetBeans, navigate to Window -> Services to open the Services window. You’ll see a tab named Databases within the window. Right-click on the MySQL Server entry, choose the Properties option, and enter your administrator password within the Basic Properties tab. Close the window and expand the MySQL Server tab, and you’ll be presented with a list of available databases. From there you can connect to a database, peruse the available tables, and even create new tables, alter table structures, and manage data, as depicted in Figure 5.

Browsing MySQL Tables from Within NetBeans
Figure 5. Browsing MySQL Tables from Within NetBeans:
Expand the MySQL Server tab and you’ll be presented with a list of available databases.

Conclusion

Although the vi vs. Emacs war grows tiresome at times, the reasoning behind this enduring technical civil war is obvious: code editors are a crucial part of a developer’s professional life. Like a woodworker’s favorite brand of power tools or a hunter’s choice of ammunition, the reasoning behind such preferences may not always be clear. However, most developers will nonetheless insist on the superiority of their IDE choice on the simple grounds that it is most productive when working in their environment. While my own technology preferences tend to be less ideologically based than others, I’d nonetheless agree that identifying and sticking with a specific IDE over the long term will undoubtedly make you a more efficient developer.

As this article indicates, NetBeans provides PHP developers with access to a powerful set of features capable of greatly enhancing productivity at all stages of development. And we didn’t even get into the debugging or testing features — I’ll save that for a later article! If you’re using a particular feature not mentioned in this article, tell us about it in the comments!

About the Author

Jason Gilmore is the founder of EasyPHPWebsites.com. He is the author of several popular books including, “Easy PHP Websites with the Zend Framework“, “Easy PayPal with PHP“, and “Beginning PHP and MySQL, Third Edition“.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories