PHP Editor Tasks: Quick Reference

This topic describes common tasks you perform in the NetBeans IDE PHP Editor. For more detailed information, click the links in the right column.

To perform this task Follow these steps
Create a new PHP project.
  1. Choose File > New Project (Ctrl-Shift-N). The New Project wizard opens.
  2. Choose PHP Application. You create a new PHP project with an empty index.php file.
  3. In the Name and Location panel, name the project. Set the project's location in the Sources Folder field. Note that you do not have to place the project in your web server's public folder. You can also store NetBeans metadata in a separate folder.
  4. In the Run Configuration page, set the default run configuration. Select whether to run the application as a local web site, a remote web site, or a command-line script. If you are running the application as a local web site, you can change the URL. If you have the sources in a different folder than your web server's public folder, copy the sources to your web server's public folder.
  5. In the Frameworks panel, you may select a framework.

For more information, see .

Import an existing local PHP application into a new NetBeans IDE PHP project.
  1. Choose File > New Project (Ctrl-Shift-N). The New Project wizard opens.
  2. Choose PHP Application from Existing Sources.

For more information, see .

Add and set a run configuration. All projects have a default run configuration. You set the default run configuration in the Run Configuration window of the New PHP Project wizards.
You can add additional run configurations to a PHP project. You can add an unlimited number of run configurations to a project. To add a run configuration to a project:
  1. In the Projects window, right-click the project's node and choose Properties. The Project Properties dialog opens. (Note: You can also select the project, go to the dropdown list of run configurations in the IDE's top toolbar and select Customize.)
  2. In the Categories pane, select Run Configuration. The Run Configuration properties open.
    PHP project properties dialog, showing
                                 Categories pane with Run Configuration chosen
  3. To define a new run configuration, click New next to the Configuration dropdown list.
    PHP Run Configuration properties,
                                 showing Configuration dropdown list and New button
    The Create New Configuration dialog box opens.
  4. Give the configuration a meaningful name.
  5. In the Run As dropdown box, select whether to run the project as a local web site, a remote web site, or a script.
  6. Complete the Run Configuration dialog depending on the type of run configuration:

For more information, see .

Select a run configuration.
  1. Select the project in the Projects window, or open any of the project's files in the editor. The project's run configuration appears in the Set Project Configuration field in the top toolbar.
  2. Select another run configuration in the top toolbar. (Note: You can also select the run configuration in the Project Properties.)
Run a PHP application as a script. You can set the run configuration of a PHP project to run the application as a script. You can set either the default run configuration or add more run configurations.
  1. If the project already exists, add a run configuration and specify that the run configuration runs as a script.
    Project Properties dialog
                                 showing Run Configuration properties, with Run As...Script selected
  2. To specify the location of the PHP engine, click the Configure button next to the Use Default PHP Interpreter box. The PHP Options dialog opens on the General tab.
    Options window open on PHP options,
                                 General tab, showing relevant fields for running PHP as script
  3. In the PHP 5 Interpreter field, specify the path to the php.exe file.
  4. To specify how the script execution results will be shown, select the relevant checkbox in the Open Result In area. The following options are available:
    • Output Window. The results of executing a script will appear in the output window in the bottom of the NetBeans IDE window.
    • Web Browser. The default browser window will open with the results of executing a script in the form of an HTML file.
    • Editor. The results of executing a script will open as an HTML file in the IDE editor window.
  5. Click OK. The Options dialog box closes and the system returns to the Run Configuration panel.

For more information, see .

Import or create a remote PHP application over FTP/SFTP. NetBeans provides basic support for FTP/SFTP, sufficient for a lone developer to work on a simple project. If you are working on a complicated project or with multiple developers, you should use a version control system. NetBeans IDE supports a number of version control systems and other collaborative development tools. See About Collaborative Development. If you must use FTP/SFTP with a complicated project, consider using the IDE in combination with a full-featured FTP client, and editing the PHP project in the IDE as a local web site.

To set up a remote PHP application over FTP/SFTP:

  1. If you are creating a NetBeans project for a PHP application on a remote server, or a new project that uses a remote run configuration as default, launch New Project > PHP > PHP Application from Remote Server. The Remote Connection page opens.

    If you have an existing project and want to upload it to an FTP server, add a run configuration to the project and specify that the run configuration runs as a remote web site. The Run Configuration dialog opens with Remote Connection fields.

    Project Properties for the Run Configuration category with Run As 
                                 Remote Web Site chosen
  2. If you do not have a preconfigured remote connection, click Manage next to the Remote Connections drop down box. The Manage Remote Connections dialog opens. Specify the new connection in this dialog. See .
  3. Select a remote connection from the Remote Connection drop-down list.
  4. In the Upload Directory field, enter the name of the subfolder in the initial directory where the source files will be uploaded. The prompt below the field shows the FTP host URL.
  5. Select whether to upload files manually, on save, or on run.
  6. Click Finish.

For more information, see .

Debug a project. To debug a project, you must have a debugger configured for your PHP environment. See .
  1. Set breakpoints in the files you want to debug. To set a breakpoint, left-click the line number or press Ctrl-F8.
  2. Right-click the project's node and choose Debug.
  3. To execute code line-by-line, press F7 (Step In). To cancel line-by-line execution, press Ctrl-F7 (Step Out). To skip to the next breakpoint, press F8 (Step Over). You can use the debugger toolbar instead of function keys.

For more information, see .

Use remote debugging or symbolic links. NetBeans IDE for PHP provides Path Mapping to handle remote debugging and symbolic links. Path mapping is set for a run configuration. To set up path mapping:
  1. Right-click the project's node in the Projects Window and select Properties. The Properties dialog opens.
  2. Select the Run Configuration category. The Run Configuration options appear.
  3. Click the Advanced button. The Advanced Web Configuration dialog appears.

    Note: The Advanced button is not available on projects that run as scripts. Also note that you may need to expand the dialog screen to see the Advanced button.

  4. In the Advanced Web Configuration dialog, click New next to the Path Mapping table to add a Path Mapping.
  5. Select whether to use the default URL for debugging, to have the IDE ask you for the URL at the beginning of every debug session, or not to open a web browser automatically for each debug session.
  6. Set the debugger proxy, if any.

For more information, see .

Add framework support to a project. You have to install the PHP framework separately. NetBeans currently supports Zend, Symfony, and Smarty frameworks. The Smarty framework support is community-contributed. To use framework support:
  1. Go to Tools > Plugins and install the plugin for the framework you want to use.
  2. Create a new PHP project. In the last page of the New PHP Project wizard, select the framework you want to use. The IDE generates the project with the skeleton for the framework.
  3. To run a command for the framework, right-click the project's node in the Projects window and select [name of framework] > Run command... You can set a shortcut for this in Tools > Options > Keymap.

For more information, see the relevant screencast in the .

Test a PHP project. NetBeans Editor for PHP supports PHPUnit and Selenium. To use PHPUnit, you have to install PHPUnit separately. After you install PHPUnit, go to Tools > Options > PHP > Unit Testing and put in the path to your PHPUnit executable file.

To use PHPUnit:

  1. Add some possible values to test in your code, using the PHPUnit @assert annotation in comment blocks.
  2. Right-click the file's node, or the parent Source Files node, in the Projects window and select Tools > Create PHPUnit Tests.
  3. Either test the entire project, by right-clicking the project's node and selecting Test (Alt-F6), or test an individual file, by right-clicking the file's node and selecting Test (Ctrl-F6). The IDE shows results in the Test Results and Output windows.

You can add code coverage to the test by right-clicking the project's node and selecting Code Coverage > Collect and Display Code Coverage.

You can use the Selenium framework to test a project. Install the Selenium plugin for the IDE. To use Selenium, right-click the project's node and select New > Other > Selenium > Selenium Test Case for PHP. Then right-click the project's node and select Run Selenium Tests.

For more information, see

Change tabs, alignments, spacing, color, or other code formatting in a project.

Color and fonts are changed in general IDE options. Tabs, alignments, spacing, etc can be changed either in general IDE options or for a specific project.

To change color and fonts, go to Tools > Options. The Options dialog opens. Select Fonts and Colors. For help, press Help.

To change tabs, alignments, or spacing:

  1. Right-click the project's node in the Projects window and select Properties. The Properties dialog opens.
  2. Select Formatting. The Formatting options appear.
  3. Select either global formatting options or project-specific formatting options. If you select project-specific formatting options, you can import these settings from another project.
  4. To change global formatting options, press Edit global options. This opens the Tools > Options > Editor dialog on the General tab. Change to the Formatting tab. The UI for this tab is identical to the UI for project-specific formatting options.
  5. Select whether to change general options for all languages, including HTML and CSS, or the PHP options.
  6. If you select the PHP language, choose Tabs and Indents, Spaces, Alignment, Braces, Blank Lines, or Wrapping. You can change a number of options for each of these categories.
For more information, see the .
Work with a file outside a project.
  • To open the file, press File > Open File... and browse to the file location.
  • To run the file, press Shift-F6.
  • To debug the file, press Ctrl-Shift-F5.
Add libraries and other files that are not source files to the PHP Project.
  1. Right-click the project's node in the Projects window. The Project Properties dialog opens.
  2. Under Categories, select Include Path. The Include Path options appear.
  3. Click Add Folder. The Select Folder(s) dialog box opens.
  4. Select the relevant folders and click Open. You return to the PHP Include Path panel. The new folder is added to the list of included folders.

Legal Notices