Finally, we are going to create a NetBeans PHP project to have the PHP content organized, and get more control over the created project.
In order to create a NetBeans PHP project, follow the steps below:
1. In order to start the project creation, go to File | New Project from the IDE menu bar.
2. From this window, choose PHP for the project category, and select PHP Application that is selected by default, which means we are going to create a PHP project from scratch. If you already have source PHP code, then go for PHP Application with Existing Sources, and you will have to browse to your existing sources to set your source directory.
3. Click on the Next button, which will take you to the following screen, as shown below:
4. Define the project name and IDE, which automatically suggests the source folder for the given name. However, we can explicitly define the source folder path by browsing the folder path. Also, choose the appropriate PHP Version, according to which the project will behave at the IDE, and select Default Encoding. We will go for the selected items, by default, to have the latest PHP version behavior, and
UTF-8
as Default Encoding.5. Remember that the project metadata is the data that is used only at the local stage; optionally, you may put the project metadata created by NetBeans into a separate directory. To do that, check the box Put NetBeans metadata into a separate directory.
6. So, we name our project as
chapter1
, and click on Next, as shown in the following screenshot:7. Define where the project will run (remote server, and so on), as well as the project URL. The default project URL is a formation of
http://localhost/
concatenated with a trailing project name. Click on Next to get to the following screenshot:Optional checkboxes are used to add the PHP framework support into your project, if required. The IDE supports the two popular PHP frameworks—the Symfony and Zend frameworks.
8. Finally, click on Finish to complete the project wizard, and NetBeans will open the PHP project. It should look similar to the following screenshot:
An index page,
index.php
, is created inside the project source automatically.9. To test the project, we will put some code between PHP tags. So, let's put a simple
echo
as follows:<?php echo "Hello World"; ?>
10. Save the file and point your browser to a project URL,
http://localhost/chapter1/
. The page should give an output similar to the following screenshot:So, we can see that our PHP project is performing fine.
11. To add more files and classes into our project, you may right-click on the project name, which will show the Project menu:
With this project context menu, we can add more PHP files, classes, and so on from New, whenever required. As we can see in this screenshot, a project can be modified as well. For example, you can rename, copy, or alter the project configuration, should you so wish.
Creating a new PHP project in NetBeans has worked like a charm. While creating it, we have observed that we can easily set several configurations of a project with the help of the step-by-step project creation wizard. Also, we have seen that after the creation of a new project, the IDE supports new PHP files, classes, interfaces, and so on from the project context menu. Note that, from the project context menu, you can manage the project operations, such as running and versioning tasks. To change the settings of an existing project, position the cursor on the project node, and choose Properties from the pop-up menu.
So, from now on, these will be our steps to create a new PHP project in NetBeans.