install Netbeans PHP IDE in Ubuntu

September 16, 2017 in Web Server

install Netbeans in Ubuntu.

Installing required software.

Before we install Netbeans we need to install Apache2 and Php.

sudo apt-get update
sudo apt-get install apache2 php

Now lets install Netbeans

sudo apt-get install netbeans

Now we need to add the php support for Netbeans. go and download that from the official website https://netbeans.org/downloads/index.html

Once the download completes then do to Downloads directory make the file executable and run it.

cd ~/Downloads/
sudo chmod +x netbeans-8.2-php-linux-x64.sh
./netbeans-8.2-php-linux-x64.sh

Then follow the wizard and install it.

This script will update the Netbeans and add php components into the IDE.

before we create a new project we need to add write permissions in the Apache root directory so netbeans will  be able to write directly into this directory.

sudo chmod 777 /var/www/html/

Lets create a new project.

Open Netbeans from Ubuntu Menu and click on "File" and then "New Project"

Select "PHP" --> "PHP Application" and click "Next"

Then change the project name and click next.

 

On the next window click the check box "copy files from Sources Folder to another location" and add the "html" after "/var/www/"

 

Now click finish and lets create a small php project where we will try to authenticate a user.

in the index.php just delete everything and copy the following:

<?php
   ob_start();
   session_start();
?>
<html lang = "en">
   
   <head>
      <title>allaboutlinux.eu</title>
      <link href = "css/bootstrap.min.css" rel = "stylesheet">
    
      
   </head>
	
   <body>
      
      <h2>Enter Username and Password</h2> 
      <div class = "container form-signin">
         
         <?php
            $msg = '';
            
            if (isset($_POST['login']) && !empty($_POST['username']) 
               && !empty($_POST['password'])) {
				
               if ($_POST['username'] == 'allaboutlinux.eu' && 
                  $_POST['password'] == 'aal.eu') {
                  $_SESSION['valid'] = true;
                  $_SESSION['timeout'] = time();
                  $_SESSION['username'] = 'allaboutlinux.eu';
                  
                  echo 'You have entered valid use name and password';
                  header("Location: http://localhost/allaboutlinuxeu/correct_password.php");
               }else {
                  $msg = 'Wrong username or password';
               }
            }
         ?>
      </div> <!-- /container -->
      
      <div class = "container">
      
         <form class = "form-signin" role = "form" 
            action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']); 
            ?>" method = "post">
            <h4 class = "form-signin-heading"><?php echo $msg; ?></h4>
            <input type = "text" class = "form-control" 
               name = "username" placeholder = "username" 
               required autofocus></br>
            <input type = "password" class = "form-control"
               name = "password" placeholder = "password" required>
            <button class = "btn btn-lg btn-primary btn-block" type = "submit" 
               name = "login">Login</button>
         </form>
			
         
         
      </div> 
      
   </body>
</html>

Then lets adds one more php file that will just say "Login succesfull" if you provide the right username and password.

Right click on "Source files" --> "New" --> "PHP File…" and give the filename that we added in the index.php as redirected page. In this case "correct_password.php". Delete everything and paste the following:

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        // put your code here
        echo("Login succesfull");
        ?>
    </body>
</html>

Now click on "Run" --> "Rub Project" or hit "F6″. If everything was right then you should see a login page and if you give as username "allaboutlinux.eu" and password "aal.eu" you will get redirected into the correct_password page.

Have fun! Create your own pages and post your results here.