Develop PHP Web Applications with NetBeans, VirtualBox and Turnkey LAMP Appliance

Exclusive offer: get 50% off this eBook here
PHP Team Development

PHP Team Development — Save 50%

Easy and effective team work using MVC, agile development, source control, testing, bug tracking, and more

$20.99    $10.50
by Alfonso V. Romero | August 2009 | Open Source PHP Web Development

In this article by Alfonso Romero, we will learn how to configure NetBeans, VirtualBox and the Turnkey LAMP Appliance to develop complex PHP applications in a virtual environment. This article explains the process of creating a virtual machine, configuring the NetBeans PHP IDE, and managing a WordPress project with NetBeans in a step wise manner.

A couple of days ago, a client asked me for an easy way to develop PHP applications. Naturally, I told him the best way would be to pay me for doing it! Just kidding…

"Use the NetBeans IDE", I said to him, almost automatically. "But… isn’t NetBeans something related to Java?" he answered back, with a startled grin on his face.

"My dear friend, you can use NetBeans to develop software on Java, PHP, C++, and almost any other programming language I’ve heard of! You could even use it to work on a WordPress live Web site!" I said to him triumphantly. And that’s when a small light bulb lit up inside my mind... I introduced him to VirtualBox and the world of virtual machines, the Turnkey Linux LAMP appliance, and how to make all these software applications collaborate between each other. And that’s how this article was born.

So now, my dear readers, let’s get on with the action! Oh, and feel free to skip any section you don’t need, ok?

Download and Install VirtualBox

Go to the VirtualBox Web site and download the most recent version: http://download.virtualbox.org/virtualbox/3.0.4/VirtualBox-3.0.4-50677-Win.exe

After downloading VirtualBox, install it with all the default options (remember to register with Sun!).

Download the Turnkey LAMP appliance

Go to the Turnkey Linux Web site and download the LAMP appliance: http://www.turnkeylinux.org/download?file=turnkey-lamp-2009.02-hardy-x86.iso .

Download the NetBeans PHP IDE

Go to the Sun Web site and download the NetBeans PHP IDE here. After downloading NetBeans, install it with the default options.

Create a virtual machine

Open VirtualBox and click on the New button to create a virtual machine (VM). In the following screenshot I used the VirtualPHPDev name for my VM, but you can use whatever you want; just don’t use strange characters or signs:

PHP Team Development

Choose Linux and Ubuntu as the Operating System and Version, respectively. Click on Next to continue. Leave the default values for RAM and hard disk. When finished, click on the VirtualBox Settings button to open your virtual machine’s settings dialog, select the CD/DVD-ROM category, enable the Mount CD/DVD drive option, select the ISO Image File button and then click on the Invoke Virtual Media Manager button PHP Team Development.

PHP Team Development

Click on the Add button in the Virtual Media Manager to open up the Select a CD/DVD-ROM disk image file, go to the directory where you downloaded the Turnkey LAMP appliance and double-click on it to add it to the Virtual Media Manager:

PHP Team Development

Click on Select to close the Virtual Media Manager, and then click on OK to exit the Settings dialog. Now you can click on the Start button to start your LAMP virtual machine:

PHP Team Development

Select the Install to hard disk option in the Turnkey Linux menu screen and press Enter to start installing the LAMP appliance on your virtual machine. Eventually the following screen will show up:

PHP Team Development

Select the Guided option and press Enter to continue. The installer will ask if you want to save changes to disk. Select Yes and press Enter. The installer will start the disk formatting process and then you’ll get to the root password screen. Type the password twice for the root user, and then do the same for the MySQL user. The installer will continue and, after a while, the following installation completion screen will show up:

PHP Team Development

Select No, press Enter and then close the virtual machine typing shutdown -r now at the system prompt. You’ll return to the VirtualBox main screen. With your LAMP virtual machine selected, click on the Settings button to open the settings dialog box. Select the CD/DVD-ROM category and disable the Mount CD/DVD drive option. Then select the Network category, change the Attached to: option to Bridged Adapter and click on OK to continue:

PHP Team Development

You can start your LAMP virtual machine now. When ready, the following screen will appear:

PHP Team Development

The Bridged Adapter mode lets your virtual machine act as if it were another PC on the LAN, and consequently, it will have a different IP address. Write down the IP address shown in the Turnkey Linux Configuration Console screen, because you’ll need it to configure the NetBeans IDE later. You can minimize the LAMP virtual machine window now.

PHP Team Development Easy and effective team work using MVC, agile development, source control, testing, bug tracking, and more
Published: September 2009
eBook Price: $20.99
Book Price: $34.99
See more
Select your format and quantity:

Configuring the NetBeans PHP IDE

Now you can open your NetBeans IDE and create a new project. Choose File | New Project… from the main menu, select the PHP Application project and click on Next to continue:

PHP Team Development

Choose a name for your project and click on Next to continue:

PHP Team Development

On the next screen, select the Remote Web Site option on the Run As: field, replace localhost with the IP address of your LAMP virtual machine on the Project URL field and click on the Manage button to configure the remote connection for your virtual LAMP appliance.

The Create New Connection dialog will show up. Choose a name for your remote connection, select SFTP as the Connection Type and click on OK to continue:

PHP Team Development

On the Manage Remote Connections dialog, type the IP address of your virtual machine in the Host Name field, type root in the User Name field, type the password you assigned to your virtual machine’s root account in the Password field and click on OK to continue:

PHP Team Development

You’ll return to the New PHP Project dialog box. Click on Finish to continue:

PHP Team Development

NetBeans will return to the main screen and the new project will open up. To test the configuration, type:- echo "Testing my LAMP virtual appliance"; in the code window, and click on the Run Project button:

PHP Team Development

The Remote Upload dialog will appear next with a list of the files that will be uploaded to your LAMP virtual server. Click on OK to continue:

PHP Team Development

A Warning dialog will appear to tell you about the authenticity of your virtual machine host. Click on Yes to continue:

PHP Team Development

NetBeans will upload the PHP file to your LAMP virtual server and your Web browser will open up, showing the PHP code you wrote:

PHP Team Development

Now you can start developing PHP apps with NetBeans and your LAMP virtual server! In the next section I’ll show you how you can use NetBeans to manage PHP code in a WordPress live Web site.

PHP Team Development Easy and effective team work using MVC, agile development, source control, testing, bug tracking, and more
Published: September 2009
eBook Price: $20.99
Book Price: $34.99
See more
Select your format and quantity:

Managing a WordPress project with NetBeans

And now let’s squeeze some of the real juice out of NetBeans! In the next exercise I’ll show you how to manage a complex project: Download a copy of WordPress from http://wordpress.org/latest.zip, unzip it in your hard drive (I used the default Desktop/wordpress-2.8.4 directory when downloading from Mozilla Firefox) and then create a new project in NetBeans. This time use the PHP Application with Existing Sources option, because you’ll import all the WordPress files into your new project:

PHP Team Development

Click on Next to continue. On the next dialog you need to click on the Browse button to go and select the directory where you unzipped WordPress:

PHP Team Development

Click on Open to continue. NetBeans will take you back to the New PHP Project dialog. Click on Next to continue, select the Remote Web Site option on the Run As: field and replace localhost with the IP address of your LAMP virtual machine on the Project URL field. You can use the Turnkey LAMP remote connection you created before. Click on Finish to continue:

PHP Team Development

NetBeans will create your new project and the index.php page will show up. Before using your WordPress installation, you need to create a database in your LAMP virtual appliance. Open your Web browser and type https://ipaddress-of-your-appliance:12322 to open PHPMyAdmin (remember to replace the IP address of your virtual machine).

NOTE: If you receive a Secure Connection Failed error like the one shown below, just click on the Add Exception… button:

PHP Team Development

The Add Security Exception dialog will appear next. Click on the Get Certificate button and then on Confirm Security Exception to continue:

PHP Team Development

Now the Welcome to PHPMyAdmin screen will show up. Type: - root as the username and enter the password you assigned to your MySQL root user when installing the Turnkey LAMP appliance. Now you can create the database for your WordPress project. I chose the WordPressVB name for my database, as shown below:

PHP Team Development

Close PHPMyAdmin and go back to NetBeans. You need to create a wp-config.php file before uploading the WordPress project. Open the wp-config-sample.php and edit the DB_NAME, DB_USER and DB_PASSWORD lines with the correct values for your WordPress project:

PHP Team Development

Select File | Save As… on the main menu, replace the wp-config-sample.php name with wp-config.php and click on Save to create the wp-config.php file.

Now you can upload your WordPress project. Click on the Run Project button and NetBeans will start to upload WordPress to your virtual appliance. The Remote Upload dialog will show you a list of the files that will be uploaded to your LAMP virtual server. The first time it will upload all WordPress files, so be patient. Click on OK to continue and wait for NetBeans to upload all the files to your virtual server. Once the uploading is done, the WordPress installation page will show up in your Web browser. Fill in the Blog Title and E-mail fields, and click on Install WordPress to continue:

PHP Team Development

Follow the WordPress installation instructions and you’ll end up with your very own WordPress project installed in your virtual LAMP machine! In the following screenshot, I modified the PHP code in the header.php file to add the Turnkey LAMP image:

PHP Team Development

Now you can take full advantage of the NetBeans IDE to work with complex projects, like the WordPress blog, or make your own projects! NetBeans has a lot of tools to make your developing chores easier than you ever thought possible!

Summary

In this article, I showed you how to configure NetBeans, VirtualBox and the Turnkey LAMP appliance to develop complex PHP applications in a virtual environment. One of the biggest advantages, I see with this configuration is that you don’t need to mess up your main computer, since all the dirty stuff is done in the Turnkey LAMP virtual appliance, thanks to VirtualBox

Using the Remote Connection feature, you’ll just need to install the NetBeans PHP IDE on your main PC, and this wonderful piece of software will take care of the tedious process of having to edit and upload files to your Web server. And if something goes wrong, you won’t mess up your main computer! Just delete your virtual machine, create a new one, reinstall Turnkey LAMP, and voila! Since you have the source code of your project on your local machine, you won’t lose valuable information!

Oh, and you’re not limited to PHP development. The Turnkey Linux Web site has several virtual appliances you can use with VirtualBox and NetBeans as a starting point to develop complex Web applications based on open source software: WordPress, Joomla!, Drupal, LAMP, Tomcat (Java Servlets and JSPs), Rails, phpBB, and much more!


Further resources on this subject:


About the Author :


Alfonso V. Romero

Alfonso Romero is a freelance computer consultant and translator from Mexico. He's been working with Linux and open source software since 1999. He started operating his first web server (Apache) from a PC at home, offering free hosting services to experiment with Postfix, Squirrel Mail, MySQL, Apache, Tomcat, and Virtual Hosting. Since then, he's been working as a computer consultant for several clients in Mexico – writing Java, C++, and Web applications. Since 2000, he has worked for Pearson Education in Mexico as a computer books freelance translator and consultant. His latest book translations are the Spanish versions of Java How to Program, Seventh Edition, from Deitel & Deitel, and C++ How to Program, Sixth Edition, also from Deitel & Deitel. Al enjoys writing tutorials and teaching about Java, C++, PHP, the Apache Web server, Tomcat, MySQL, Web applications like Apache Roller, and all of the wonderful open source applications used today, and when he's not experimenting with new trends in Open Source applications, he enjoys playing his electric guitar.

Books From Packt

WordPress MU 2.7: Beginner's Guide
WordPress MU 2.7: Beginner's Guide

Joomla! 1.5 Development Cookbook [RAW]
Joomla! 1.5 Development Cookbook [RAW]

Joomla! 1.5 SEO
Joomla! 1.5 SEO

Cacti 0.8 Network Monitoring
Cacti 0.8 Network Monitoring

Asterisk 1.4 – the Professional’s Guide
Asterisk 1.4 – the Professional’s Guide

Drupal 6 Search Engine Optimization
Drupal 6 Search Engine Optimization

Symfony 1.3 web application development
Symfony 1.3 web application development

Apache Struts 2 Web Application Development
Apache Struts 2 Web Application Development

Your rating: None Average: 4.3 (4 votes)
Great tutorial by
First rate information in this article, many thanks.
Great tutorial by
I also recommend to look at Codelobster PHP Edition
Best tutorial ever. Period. by
If you follow it and do not try to be smarter than it, you will get the thing running WITHOUT A hitch. Thank you. Lanny
Great information by
Thanx for sharing with us this informatio,and thanx to sun for making our life easyer.
this is wonderful tutorial by
this is wonderful tutorial .. i read it 3 times and get a fantastic results and sure i put a copy of this lesson on my site here http://www.iksai.org

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Q
r
8
P
h
h
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software