Last updated May 21, 2014. Created on January 8, 2011.
Edited by colan, Perignon, jakobdo, stevepurkiss. Log in to edit this page.

NetBeans is a platform-independent, Java-based open source integrated development environment (IDE) which supports a wide variety of languages, including PHP.

In addition to its speed and refactoring capabilities, it offers the following:

  • Formats your code according to Drupal Coding Standards
  • It recognizes Drupal specific file extensions (.info, .module .install etc.)
  • Replaces tabs with spaces
  • Stores line breaks in UNIX format
  • Character encoding of files can be UTF-8 by default
  • Provides autocompletion with hint support for functions and classes project-wide, including Drupal core (provided core is in your project directory
  • Code templates available for Drupal hooks
  • Supports SVN and GIT version control systems

Note: These directions have been mostly updated to correspond to the current version of Netbeans (7.1.1 at this time). Most images are still from Netbeans 6.9 and were not changed if the setup was not significantly different. (LoMo — March 8, 2012)

Note: Windows users see to set up Netbeans, Xdebug, Drupal Dev Tools and Templates with Windows 7/XP and Acquia Dev Desktop (c11a - 11/21/2012)


Download the latest stable version of NetBeans, either the PHP bundle or the bundle labeled “All” (support for Java SE/EE and C/C++ as well). The page will offer the right version for you based on your browser’s operating system, but you can also select other platforms from the top-right drop-down menu.

After downloading, follow the instructions given by the installer. When the installation is complete, locate the Tools > Plugins menu item, choose the Installed tab, and activate the PHP plugin, if not already active.

NetBeans plugins

Setting up Drupal Coding Standards

After you have activated the PHP plugin, go to Preferences (or Tools > Options) > Editor > Formatting, choose PHP in the “Language” drop-down, and choose Tabs And Indents from the “Category” drop-down. You should uncheck the "Use All Language Settings" checkbox in order to continue. After that use the following settings:

  • Expand tabs to spaces: (check)
  • Number of Spaces per indent: 2
  • Tab size: 2
  • Right margin: 80
  • Initial Indentation: 0
  • Continuation Indentation: 4 (if a new row is started within a condition)
  • Array Declaration Indentation: 2
NetBeans tabs and indents

After that, choose Alignment from the category drop-down, and set "else and elseif" and "catch" to start in a new row:

NetBeans alignment

Choose Braces from category drop-down and set everything to "Same line":

NetBeans braces

Choose Blank Lines from category drop-down and set 1-1 blank lines to be used before and after functions:

NetBeans blank lines

The last category is "Spaces". You should use the following settings here:

  • Before keywords
    • Check while, else, catch
  • Before parentheses
    • Uncheck Method / Function Declaration, Method / Function Call, Array Declaration
    • Check if, for, while, catch, switch
  • Around operators
    • Uncheck Unary and Object operators
    • Check Binary, Ternary, String concatenation, Key => Value and Assignment operators
  • Check all options in "Before Left Braces"
  • Uncheck all options in "Within parentheses"
  • Other
    • Uncheck “Before Comma” and “Before Semicolon”; check all others

When you have finished these steps, the code formatting will be just as required by the Drupal Coding Standards.

Setting up Drupal-specific file extensions and Drupal core functions

Go to Preferences (or Tools > Options) > Miscellaneous > Files, and click New on the Files tab. Add the following extensions one by one:

  • module
  • install
  • test
  • profile
  • theme
  • engine

Associated file type (MIME) type should be text/x-php5 (for PHP files).
Finally, add the "info" and "po" extensions with MIME type: text/plain.

NetBeans files

Now NetBeans will recognize these filetypes. The next step is to allow it to autocomplete Drupal core functions. For this to happen you need to download Drupal and extract the files to a folder (you don’t need to install it, you just need the files, so that NetBeans can read the functions), go to Preferences (or Tools > Options) > PHP > General, and add the folder to the Global include path list.

If you are also developing Drush-compatible modules, you should add the Drush folder to this list, to be able to use Drush functions.

NetBeans lib

Setting up Drupal hook templates

You just need to download the NetBeans Templates project, and import the extracted [.ZIP] file in Preferences (or Tools > Options) > Editor > Code Templates. Please note that the import process will require a Netbeans IDE restart, so ensure you have saved all your preferences before running the template import.

NetBeans templates

Using version control systems

(Note/Update: Netbeans 7.x includes Git and is active, by default).
NetBeans supports CVS by default, but GIT can also be installed easily. You just need to download the plugin and install it.


After you have set up localhost, and installed your Drupal, create a new PHP project with File > New Project, PHP, PHP Application with Existing Sources.

NetBeans new project

After clicking “Next”, you can set your project’s properties. I suggest using the sites folder of your installed Drupal as Sources folder. Select 5.3 for PHP version and UTF-8 for encoding. You don’t need to store Netbeans metadata in a separate directory.

NetBeans project data

Now you can click “Finish”, and you will see your newly-created project. After creating a new file, you can use the autocomplete, and you are ready to use your NetBeans for Drupal development.

NetBeans autocomplate

The Hungarian version of this page at here

nb_alignment.jpg-1.jpg124.02 KB

Looking for support? Visit the forums, or join #drupal-support in IRC.


antonyanimator’s picture

Great tutorial thanks,

Preferences however is the wrong description in linux and windows net beans, it should be tools > options

asangdani’s picture

I have tested this on Ubuntu 10.04 with php 5.3.2 and xdebug 2.0.5. There are several issues like local variables don't correctly display and debugging session terminates prematurely. As explained at:

I have updated xdebug to 2.1.1 and everything works fine.

Hope this helps others.


Reevescorp’s picture

Before you import the Netbeans templates project SAVE the settings you already entered. Netbeans may require a restart to import the templates and if it does everything you just entered will be lost.

tinker’s picture

I installed Netbeans 6.8 which was included in my linux distro only to find out that it does not support GIT version control. A GIT plugin is available starting with NetBeans 7.0 beta 2. You can get the latest package at

phunster’s picture

At least for me it does

tsvenson’s picture

Was looking at the nbgit plugin, but it seems to be pretty dead as no work have been done for a year. It also doesn't seem to have an Netbeans 7 versions. seems to be the official git support being worked on by developers at Oracle.

Documentation can be found on

Jamie Holly’s picture

NBGit works up to 7.0.1. Git support is native in Netbeans starting in 7.1, so that's why the project is pretty much abandoned at this point.


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

Khellus’s picture

One rarely sees such a well explained walk through, great job.

pfrenssen’s picture

Set the right margin to 80 instead of 120, as per the coding standards.

Jamie Holly’s picture

I've developed a module for doing Drupal development in Netbeans. It's for 7.0+ only. You can grab the NBM here:

The project is GNU, so if anyone wants to fork it or help contribute to it, just let me know. Right now it's at version 1.5.2, but I've already started work on the 2.0 release, which will have Drush integration built in.


HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

wildfeed’s picture

This is an incredible tool when using Netbeans to develop Drupal code.
You can run Drush commands and reference Drupal hooks right from the IDE.

Frank Ralf’s picture

amontero’s picture

Since 7.1, NetBeans integrates Git.
You can read more at NetBeans Git User Guide

pfrenssen’s picture

Older versions of Netbeans have git support thanks to the NBGit module.

rondev’s picture

Thank you very much. That is something I waited for a looong time, feeling myself useless without such a tool. You just added a new Drupal debugger to the Drupal task force.

I regret I don't manage to create git patch with an anonymous access to modules repositories. First step, if I understand, would be to use git clone. But I got an error doing that: "invalid advertisement of ?xml version="1.0" encoding="utf-8"?>"

If someone has some tips, I think it would help some people wanting to propose patch directly in the issues manager instead of copy/paste code. That would represent less work for the module maintainers who do already a lot.

rondev’s picture

As often, I found a solution after posting my issue.
I finally succeeded. I entered a bad url for the git clone.
You have to enter: Per example for taxonomy_menu, it is:
Found here #1038404: Determine an approach to managing git repositories on disk

PROMES’s picture

I just installed NetBeans v 7.1.2.
As of version 7 (?) the Toolsbar has changed:
Preferences > Editor
now can be found via:
Tools > Options > Editor.

Thanks for this great tutorial.

yokosatan’s picture

I'm using 7.1.2 too, but I get many error when I put the drupal into netbeans.
Can you solve the problem?

PROMES’s picture

I didn't get any errors or problems after installing NetBeans as written above.
Please describe the kind of errors you get to understand these.

Uccio’s picture

For all lazy people that need a clean coding template for netbeans 7.2 I exported it in :

The page it's in italian but the download it's for all countries!

Frank Ralf’s picture

Just a hint: You can feed the downloaded zip file as is to NetBeans - no need to unpack it first ;-)

bkudrle’s picture

Just a note to say that there is a Drupal project with a ready-made virtual Ubuntu environment in Quickstart. It has NetBeans already set up as well as having debugging already set up and other tools already configured. It's a nice and easy option to also get these benefits from NetBeans.

dustin.silva’s picture

It seems the file contains a file named nb_templates/ -- I have to rename the file and remove .txt extension before nb will import it..


**edit -- almost forgot to mention, Thank you so much for this write-up!! It has made the transition to drupal so much smoother!!!!!

lise.perceives’s picture

File > PHP > PHP Application with Existing Sources

should be

File > New project > PHP > PHP Application with Existing Sources

Otherwise: great page!

prabhu.murugesan’s picture

Please explain about drush folders

kalman.hosszu’s picture

I'm not really know what is your question, but if you want to create drush compatible modules, you have to know about drush functions, for example: drush_print(), drush_set_error(), dt() or drush_op(). So if you import your drush folder, the auto complete will work for drush functions too.

SharonD214’s picture

I got all the way up to the end, but when I click finish, nothing happens. I don't see any newly created project. If I try to open project and browse to my sites folder. It reads Error in project.xml: Premature end of file.

Any ideas?

francis55’s picture

Understanding anything in Drupal code without a debugger leaves you feeling like a caveman facing a computer keyboard. Now I installed Netbeans the light is starting to dawn, why didn't i do this earlier? Take the time to run through this tutorial if you have anything to do with Drupal!

Alternately, you can use the Quickstart.ova ready-made virtual image to use with VirtualBox (mentioned by bkudrle), if you prefer to run your debugger and web server in a separate environment. If you are a Windows user this will avoid possible interference with the IIS Web server, competing for ports. Check out for more info.

Nicolas Bouteille’s picture

Hi, thank you for this great article.

I can't make the auto-completion of Drupal core hooks to work for me.
I added all the files extensions and I also extracted Drupal 7.24 and added the folder to the Global include path as indicated.
What am I missing ? Do I need to make Netbeans work with MAMP or something so that PHP can be interpreted and suggestions can be made ?
From what I read on the net it works automatically for everybody...

Help !

Nicolas Bouteille’s picture

The problem was coming from the version 7.4 of Netbeans. I uninstalled everything and tried 7.3.1 instead and autocomplete worked immediately.

I would like to precise that I did not need to add Drupal in the Global include path at all. Instead of choosing the sites folder as source folder, I chose the root of my Drupal project instead. Netbeans scans all the files of the projet automatically. Which means that it autocompletes not only core drupal hooks but also contrib modules hooks and custom functions provided you documented them. I did not even need to associate drupal extensions like .module or .theme as PHP files to make it work. It works 100% out of the box.

To make the suggestions appear, just type 'drupal' or 'hook'.

I recommend to read this article which give a good overview of all the cool features of netbeans

Maybe a bit of update needs to be made on this article, which is great in any case !


Nicolas Bouteille’s picture

Just wanted to add that installing Netbeans Templates broke Netbeans and I had to reinstall it. Becareful with it.

rekaut’s picture

NetBeans Configuration for Drupal 8 fine . just tested and working , same as
in Tutorials.
thank you

JohnFF’s picture

Helped us immensely.

lanceh1412’s picture

Sometimes you will get the text 'Evaluating ...' instead of the actual value. This can be because there is not enough memory allocated to the variable. You can change this. Go to 'Tools | Options | Php' and change the value of the Maximum Data Length.


morgancartwright’s picture

I added the Drupal file extensions as outlined in this tutorial, but when I right click on a folder and choose New File, I don't see the new file types available. There are the 10 most used types displayed, then a link to Other that displays five Category folders with many more file type options, but non for the Drupal file types like .info and .module. I can select the Empty File option and use those extensions, but the NB file tree on the left shows them in green with an Unrecognized File tool tip. Is there a separate step to add the new file types to the New File dialog?