NetBeans & AMP (10 Minutes)
Description
This demo shows how to get started with PHP development with NetBeans and deploy to OpenSolaris.
OpenSolaris Versions Supported
2008.05 or newer.
Points to Hit
- NetBeans is not only a Java IDE, it supports many dynamic languages as well.
- NetBeans has very cool PHP editing featurs (code completion, instant rename, local history, etc.)
- Deploying to OpenSolaris is easy because AMP stack is well integrated into the OS.
Demo Prep
- Install latest version of NetBeans with PHP support.
- Install the webstackui package from IPS. Typically it downloads all dependencies but if it wouldn't install Apache2, MySQL, modphp and mysql library for PHP (SUNWphp524-mysql) manually.
Gotchas
Make sure you have all the required libraries (php support for Apache and MySQL library for PHP).
Demo
- Start the Apache and MySQL services using Applications | Developer Tools | Web Stack Admin | Start Apache2/MySQL servers.
- Open Firefox and go to *http://localhost*. You should see a web page loaded.
- Open terminal and go to /var/apache2/2.2/htdocs.
- Start NetBeans PHP version (not the Java version!).
- Create a New Project. You can leave the name PHPProject1, but choose to put the metadata in a separate directory (use default directory). In last step just click Finish.
- Modify index.php with following source code: <?php echo "Hello world!"; ?>
- Run the project using Project | Run Main Project.
- You should see the application running in a web browser.
- Let's connect to MySQL by running /usr/mysql/bin/mysql -uroot
- List databases by running show databases.
- Switch to database test by running /u test.
- Run:
create table test (id int primary key, name varchar(255)); insert into test values (1, "Roman"); insert into test values (2, "Brian"); insert into test values (3, "Gregg"); select * from test;
- Back to NetBeans IDE.
- Use following code:
<?php $c = mysql_connect("localhost", "root"); mysql_select_db("test"); $r = mysql_query("select * from test"); for ($i=0; $i<mysql_num_rows($r); $i++) { echo mysql_result($r, $i, "id")." ".mysql_result($r, $i, "name")."<br/>"; } ?> - Run the application in web browser using Run | Run Main Project.
Demo Cleanup
- Delete table test.
- Delete created projects.
- Delete all files deployed to Apache in /var/apache2/2.2/htdocs.