PHP is a back-end language for web development. PHP code needs to be executed by a PHP compiler in a web server. A web server will run and compile the code to the corresponding HTML code. In Netbeans IDE, we can create a PHP project with a local web server for development and test.

## PHP: Hypertext Preprocessor

PHP has a complete set of object-oriented programming features including support for classes, abstract classes, interfaces, inheritance, constructors, cloning, exceptions, and more.

OS X is bundled with PHP but it is normally a little behind the latest stable version.

A few things that you may need to learn about PHP before diving into the language:

• If a web page contains PHP code, its file extension must be php.

• PHP code is not visible to front-end users.

• PHP code can be placed anywhere in the source code of a web page.

• PHP code must be enclosed with a pair of special tags

The following will show you how to create a PHP project with NetBeans 8.2 and an xampp installation for Windows.

## Launch XAMPP

If you haven’t have xampp installed, install xampp.

Launch the control panel of xampp. Start Apache service.

## Display the PHP Errors

Error output is very useful during development, but it could be very dangerous in production environments. PHP is configured by default in a way which displays compilation errors in development environments and hide them in production environments.

As recommended by PHP:

### PHP Initialization File

In xampp, the PHP initialization file, php/php.ini, from the xampp directory, contains the following line which enables the errors as xampp constitutes a development environment:

To turn off the errors, replace Off with On.

### Enable errors in production environments

In a production environment, errors are hidden by default. If you don’t have write permission to php.ini, you can still enable error displaying for a page by add the following PHP snippet.

## Launch NetBeans

Start NetBeans IDE. Verify the HTML5 and PHP plugins are active by the menu path Tools->Plugins.

## Create a New Project

In New Project dialog box,

• Select PHP in Categories

• Select PHP application in Projects

• Click Next

In Name and Location: Make a name ‘MyWebApp’

• Browse and choose a folder for project sources. For example, C:/Documents/C430/MyWebApp

• Select a PHP version (PHP 7.0)

Click Next twice and Finish.

## Configure the Project

In the Projects tab, right-click MyWebApp. Choose Properties.

### Run Configuration

Click Run Configuration in the Categories column.

• Run As: Script(run in command line)

• Uncheck Use default PHP interpreter

• Click Browse button to navigate to php.exe in your xampp installation folder. For example, if your xampp directory is in drive L, then the path of php.exe should be: L:\xampp\php\php.exe

• In the field ‘Index File:’, enter

index.php

• In the field “Arguments”, enter

debug=true

• In the field “PHP options”, enter

-a

### Configuring sources

Click Sources in the Categories column. On the right,

• Leave Project Folder and Source Folder as it is.

• Check Copy files from Sources Folder to another location

• Copy to Folder: L:\xampp\htdocs\MyWebApp (J is the drive letter where contains your XAMPP directory.)

• Check Copy files on project open

## Insert a New PHP Web Page

Right-click the node Sources Files under MyWebApp in the Projects window.

Follow the selection: New -> PHP Web Page...

Enter index for File Name. Press Finish.

## Edit index.php

Edit the source of index.php to the following:

## Insert and Edit a New Stylesheet File main.css

index.php imports style sheets from an external css file main.css. In the following, we create such a file.

• Make a new folder “styles” in the node Source Files of MyWebApp.

• Right-click styles node to create a new Cascading Style sheet...

• Name the file main.css.

• Add the following style sheets to main.css

## Launch the Site MyWebApp

Now we can test the site by launching MyWebApp in a web browser.

• Start a web browser window or tab.

• In the address bar, enter the url:

http://localhost:81/MyWebApp

• The page should be similar to

## Test the PHP Page

To test any change with index.php`, simply reload the page in the browser window.