NetBeans overview

From Joomla! Documentation

Introduction

A brief overview of how to setup the PHP edition of NetBeans follows. You would still need to consult Setting up your workstation for Joomla! development to learn about setting up your environment for Joomla! development. For the sake of brevity and not to "reinvent the wheel" we will provide references to further readings wherever we deem various topics are treated to a satisfactory extent elsewhere.

Notes

  • NetBeans is supplied with the PHP plugin as a standard feature.
  • The following applies to all recent versions of Windows. The steps similar for other operating systems.
  • In many of the cases, there are several ways of achieving your goal. The coverage here is just a guideline for a beginner and doesn't claim to be exhaustive.

About NetBeans

NetBeans is a modern IDE that is excellent for PHP development (along with Java and several other languages). See the NetBeans IDE Features page.

Installation

Installation on Windows

To install and run NetBeans, you need to have Java installed on your system. If you're not sure, verify your Java version.

If you don't have Java, download it at java.com.

You can download Apache NetBeans.

Installation on Linux: Ubuntu 10.04

  1. Open the terminal and install NetBeans version with the following command:
sudo apt-get update && sudo apt-get install netbeans
  1. Start NetBeans (Applications → Programming → NetBeans IDE)
  2. Install the PHP plugin for NetBeans: Tools → Plugins → Available Plugins. Select PHP and install it.

Initial Configuration

  1. Your first run after installation will install the auto-update plugin. Please do restart after installing the plugin.
  2. Your second run will find a number of updates which you are advised to install.
  3. Let's install the subversion plugin which we will need further down.
    1. Go to Tools → Plugins menu.
    2. Switch to the Available plugins... tab.
    3. Look for a plugin with the name Subversion in the Base IDE category.
    4. Select it by checking the checkbox to the left and click on the Install button at the bottom of the Plugins dialogue.
    5. Restart after the installation is done and you now have a Subversion client within your IDE.
  4. The start page of NetBeans consisting of related news can be turned off by unchecking the "Show On Startup" checkbox at the top of the screen.

We are now set to go and from here we will:

  • create our first hello netbeans project and do some minor debuggings
  • step through downloading Joomla from the SVN and make changes, create patches, apply patches and get updates from the SVN.

Creating a Project and Debugging

  1. Start NetBeans and choose File → New Project menu and you will be presented with the New PHP Project wizard.
  2. Select PHP Application among the Projects options. Reference: Setting Up a PHP Project
  3. In the next step you will be given the option of configuring
    1. Project Name - enter hellonb
    2. Sources Folder - where the files created within the project will be located. Although NetBeans makes an attempt to locate the server DocumentRoot, it normally fails and defaults to Apaches default htdocs, which means if you have reconfigured DocumentRoot in your httpd.conf file, it will not be able to point it out for you. You will need to point out the location manually as follows. Go to your DocumentRoot folder by choosing Browse and in your DocumentRoot folder create the project folder hellonb. Select the folder and click Open.
    3. Put NetBeans metadata into a separate directory - NetBeans creates a folder named nbproject containing project specific IDE settings and metadata of the project to be created. If you are working with a project in which you are about to checkout from SVN, as we will see below, having this folder in your project folder is not a desired option as it eventually will be included in your patch export. One way of not having nbproject in such exports is to relocate nbproject from its default location, the project folder. This is done by simply checking this checkbox and pointing out where the nbproject folder should be located, outside your project folder. Another method will be described below.
    4. In the next page of the wizard, make sure that the Project URL is correct, in this case http://localhost/hellonb/, depending on your setup.
    5. It's now time to press the Finish button and create the project.
  4. Although NetBeans succeeds in detecting where the PHP interpreter is located and thereby also XDebug, let's make sure that this is correct by going to Tools → Options menu. Select the PHP section (among the top horizontal bar of icons). In the General tab, verify that the PHP Interpreter is the correct one and that the Debugger Port option contains the same value as the xdebug.remote_port parameter in the php.ini file of the interpreter referred to.
    1. For those who've followed the instructions at Setting up your workstation for Joomla! development to update the php.ini file with
      set xdebug.remote_port=10000
      
      you need to go to Tools → Options → PHP → General and set the Debugger Port to 10000 to match.
  5. With this behind us let us create our index.php file and put a simple statement, for example, echo "hello netbeans". Press F6 and the project should run by invoking index.php either in your default browser or one you would be able to configure in Tools → Options → General → Web Browser. With the given example, this should output hello netbeans in your browser.

Resources

Subversion Setup

In this part we will see how easy it is to work with an SVN repository for the purpose of checking out, creating patches, applying patches and updating the repository.

  1. Create a new project of the type PHP Application according to the above outline.
  2. Check if NetBeans created an index.php file in the Source Files directory. (It's located under the Projects tab.) If so, delete it before you start the checkout. If you don't, it might break the checkout process.
  3. Go to Team → Subversion → Checkout... and give the following:
    1. In Repository URL, enter http://joomlacode.org/svn/joomla/development/trunk.
    2. In User, enter anonymous
    3. Leave the Password field empty.
  4. Click Next and NetBeans will connect to the SVN repository and ask you to provide:
    1. Repository folder(s) to checkout from in the repository which should remain unchanged, being development/trunk as it was included in the Repository URL. If the field is empty for some reason provide development/trunk.
    2. Local Folder - Browse and point out your current project folder.
    3. Uncheck the Scan for NetBeans project checkbox and click Next.
    4. Checking out the trunk can take some minutes to finish and you will see the task status on the right side of the status bar.
  5. Now that the Joomla code base is checked out, it's time to install Joomla!. In order to run Joomla!, the installation folder needs to be removed or at least renamed. This creates a catch-22 because deleting the folder or changing it will result in being considered as actual change for which patch will be generated. If we don't change it, we can't run Joomla!. The solution here is to make NetBeans ignore the installation folder from here on out. Unfortunately NetBeans doesn't allow us to ignore files that are already in the SVN repository. /If you know of a better way than using external tools such as Tortoise SVN for this purpose, please edit and put it here/
  6. If you didn't choose to relocate the nbproject directory while creating the project, let us now make sure that the SVN client ignores it, that is, assure that it is not included in any patch export.
    1. In your Files pane, find the folder nbproject and right click it.
    2. Choose the Subversion → Ignore menu and once the folder is ignored it is colored gray.
  7. Let us now make a dummy change to see how to deal with the various steps of creating a patch works.
    1. Open the components/com_content/content.php file and make a change, for example, by inserting a comment. Once we have saved our change you will see that
      1. the line where the change is done is highlighted with blue to the left of the edit screen.
      2. filenames are colored with blue.
      3. the containing folders of the changed files are highlighted with a blue badge.
    2. Lets now assume that our change is a solution to a tracker we would like to submit as a patch. In NetBeans you will be able to do that at several levels, either patch extracted from the file itself only, or at an upper level up to the project level. To do that:
      1. In the Projects or Files pane, click on the folder or file you want to be the position from which all changes will be extracted as patch.
      2. Go to Team → Export Diff Patch... menu and give the location of the patch file to be generated and click OK.
    3. Applying patches is analogous and all features related to SVN are found under Team or Team → Subversion menu.

Resources

Resources