Get OpenSolaris 2009.06 Preview Release from http://genunix.org/distributions/indiana/osol-0906-111a-x86.iso
Convention used in this document are list below:
- OpenSolaris OS – OpenSolaris 2009.06 OS Preview Release.
- Web Stack – Sun GlassFish Web Stack 1.5.
- AMP – Apache, MySQL, and PHP runtime libraries (Web Stack).
- Web Stack UI – Web Stack Configuration Tool.
- NetBeans IDE – NetBeans IDE 6.5.1
NetBeans IDE and Web StacK
OpeSolaris OS offers complete support for developing and deploying applications for the web. Starting from OpenSolaris 2008.05 OS, a collection of some of the most commonly used open source applications and frameworks are bundled with the OS. These applications comprise the Web Stack and include several packages that are optimized for the OpenSolaris OS and aid in web based development in that platform.
Along with OpenSolaris OS, you can try out the NetBeans IDE, a free open-source IDE for creating professional desktop, enterprise, web, and mobile applications.
This document shows you how you can use NetBeans IDE to build web applications on OpenSolaris OS using the Web Stack components. Before we dive into the details of these components, let us enumerate the stages involved in developing an end to end enterprise grade web application.
What do you expect from an IDE if you are planning to use the IDE for web development?
- Server support – Your IDE should support managing the Server lifecycle through an intuitive and easy to use interface.
- Languages Support – You will expect the IDE to support working with the programming language or web application framework your web application will be eventually built on.
- Database support – What good is an enterprise application without a database? You want your IDE to be well integrated with your development, testing, and production database.
Typically, your development environment should enable you to build web applications with minimal effort offering you an extensive support for stack level configuration through property editors, wizards, and widgets. Server support, languages support, and database support are the three prime facets that any IDE can offer for web development.
NetBeans IDE on OpenSolaris OS takes care of all these factors with an elegant interface making web development just easy. You can build your web applications in PHP or use Rails framework and work with DBs like MySQL DB or PostgreSQL DB in NetBeans.
In OpenSolaris OS, for building and testing web applications, get the following software:
- NetBeans IDE
- Web Stack
- The Java SE Development Kit (JDK) 5.0 or higher
Web Stack is fully integrated with the OpenSolaris 2008.11 OS and can be easily installed by using the Package Manager GUI or pfexec pkg install commands.
|Component||Package Name||Command to Install|
|Apache 2.2 core only||SUNWapch22||pfexec pkg install SUNWapch22|
|Apache 2.2 modules||SUNWapch22m-security, SUNWapch22m-jk, SUNWapch22m-fcgid, SUNWapch22m-dtrace||pfexec pkg install SUNWapch22m-security SUNWapch22m-jk SUNWapch22m-fcgid SUNWapch22m-dtrace|
|PHP5 core only||SUNWphp52||pfexec pkg install SUNWphp52|
|PHP5 Extensions||SUNWphp52-mysql, SUNWphp52-pgsql, SUNWapch22m-php52||pfexec pkg install SUNWphp52-mysql SUNWphp52-pgsql SUNWapch22m-php52|
|MySQL||SUNWmysql5||pfexec pkg install SUNWmysql5|
|Web Stack user interface||webstackui||pfexec pkg install webstackui|
Note - For executing the pkg install command, you should be a root user. You can also invoke the pkg install command adding a pfexec prefix to the command as a non-root user. For instance, as a non-root user, execute pfexec pkg install SUNWapch22.
Alternatively, you can download the entire AMP package by executing the following command:
$ pfexec pkg install amp-dev
The amp-dev package is the set of all the Web Stack packages along with other development tools like the NetBeans IDE and the Mercurial. The approximate size of this package is 650 mega bytes (MB). If you are unable to download this package, you can download individual packages as shown in the following sections.
If you already have installed NetBeans IDE version 6.5.1 or higher, then you can download just the AMP components without any IDE or other tools as shown below:
$ pfexec pkg install amp
Web Stack IPS Repository
Web Stack IPS repository is an experimental repository hosting applications and tools pertaining to Web Stack. For example, you can find applications like Drupal or PHPMyAdmin in the Web Stack repository, which you can download and install instead of downloading the applications directly from the respective sites. The applications that are available in the Web Stack repository are pre-configured to work with other components in the Web Stack.
The Web Stack repository is available at http://pkg.opensolaris.org/webstack.
You can set additional repositories in Open Solaris using pkg set-repository command.
Web Stack UI
Before you can use Web Stack for web development, you need to initialize the environment for your login. Every new user logged into the system must initialize their own environment.
To download and install the Web Stack UI, execute the following command:
$ pfexec pkg install webstackui
Note - If you have already installed the amp-dev package, webstackui package is also installed. You need to install the webstackui package only when you are installing the AMP packages separately.
Since the webstackui package depends on other Apache packages, if you have not already installed the Apache Web Server, it will be automatically downloaded when you install the webstackui package. As mentioned earlier, Web Stack UI is just the GUI option to control the AMP components. You still need to download and configure AMP packages if you have not installed the amp-dev package.
After downloading and installing the amp-dev package, initialize the Web Stack environment as follows:
- Click Applications > Developer Tools > Web Stack Initialize. Enter the user password.
After installing Web Stack, Click Applications > Developer Tools > Web Stack Getting Started Guide for more information on setting up the AMP environment on the OpenSolaris OS.
After installing the Web Stack UI, you can create and run the bundled sample applications from the menu item. Go to Applications > Developer Tools > Web Stack Admin > Sample App to find these menu items.
MySQL DB support
MySQL DB is a popular Open Source relational database management system (RDBMS) commonly used in web applications due to its speed, flexibility, and reliability. MySQL Server 5.1 is available through the Web Stack software.
This section demonstrates how to obtain the DB and set up a connection to a MySQL database from the NetBeans IDE. Once connected, you can begin working with MySQL in the IDE's Database Explorer by creating new databases and tables, populating tables with data, and running SQL queries on database structures and content.
When you download and install the amp-dev package you are also installing the MySQL database. If you have not downloaded the amp-dev package, you can download only the MySQL package as shown below:
$ pfexec pkg install SUNWmysql51
You may still need to configure the MySQL Server in order for it to function properly. If you have installed the Web Stack UI package, you can start/stop the MySQL Server from the menu.
To start the MySQL Server on the OpenSolaris OS, click Applications > Developer Tools > Web Stack Admin > Start Apache2/MySQL Servers.
Perform the following steps as a root user to start the MySQL Server:
$ svccfg import /var/svc/manifest/application/database/mysql.xml $ svcadm enable -s application/database/mysql:version_51
The first command shows how you can import the MySQL Server manifest file. You need to execute this only once. To stop the server, execute the following command:
$ svcadm disable -s application/database/mysql:version_51
Note - The default password for the MySQL Server root user is a blank string (no password). Change the default MySQL Server root password before deploying it in a production environment. After starting the MySQL Server using the command provided in the previous section, you can connect to the MySQL Server using the command:
/usr/mysql/bin/mysql -u root
Registering the Server with the NetBeans IDE
You can register the MySQL Server with the NetBeans IDE so that you can manage the lifecycle of the server directly from the IDE. You need to perform the following tasks:
- Go to the Services Tab.
- Right click Databases and select Register MySQL Server...
- Enter Server Host Name as localhost, Server Port Number as 3306, Administrator Username as root. Do not type any value for the Administrator Password if you have not changed the root password. Click OK. You will see the sample tables of the registered MySQL Server.
That is all you need to work with the MySQL Server from the NetBeans IDE. You can perform many operations like creating databases and tables directly from the NetBeans IDE.
For more information, see http://db.netbeans.org/
NetBeans IDE on the OpenSolaris OS supports various Java EE servers and other web servers for application deployment. You can have multiple servers configured in the NetBeans IDE irrespective of the server that will be used in your projects. Thus you can have Apache Web Server configured for deploying PHP files, Apache Tomcat container configured for deploying Java based web applications or a WEBrick server for deploying Rails applications.
Apache2 Web Server
The Web Stack bundle comes with the Apache 2.2 Web Server. The NetBeans IDE lets you add the Apache web server in the servers list so that the applications ou build including any PHP based web applications can be deployed to the Apache web server. This section shows you how you can set up the Apache Web Server in the NetBeans IDE.
You do not need to download Apache Web Server or PHP engine separately if you have installed the Web Stack software.
To start/stop the Apache Web Server, perform the following task:
- Click Applications > Developer Tools > Web Stack Admin > Start Apache2/MySQL Servers
Testing the Apache Web Server from the NetBeans IDE
You do not need to explicitly add the Apache Web Server in the NetBeans IDE's Server's entry. Earlier versions of the NetBeans IDE (< 6.0) allowed you to add the Apache Web Server in your Server's entry by letting you provide details including the path to the htdocs directory.
The main advantage of using the NetBeans IDE 6.5.1 or higher is that you can set individual server configuration for each PHP project. The NetBeans PHP project itself contains information on which Apache Document Root directory htdocs the PHP files needs to be copied to test the project.
To test if the NetBeans IDE and the Apache Web Server combination is working for you, perform the following tasks:
- Start the Apache Web Server. Click Applications > Developer Tools > Web Stack Admin > Start Apache2/MySQL Servers.
- In the NetBeans IDE, click File > New Project > PHP > PHP Application.
- Enter TestPHP as the name of the PHP Project.
- Enter /var/apache2/2.2/htdocs/HelloPHP as the Sources Folder path. The NetBeans IDE assumes that you need to store the source files on the local web server. The NetBeans wizard detects the Apache installation type and provides the path to the default location of the htdocs folder for the current installation type.
Select the default encoding as UTF-8.
- If you need to store the NetBeans project files outside the htdocs folder, select the Put NetBeans metadata into a separate directory option and provide the path. Click Next.
- Select Local Web Site (running on local web server) for the Run As option.
- Leave the Project URL field un-modified if you have not made any changes to the Apache Web Server startup port. (http://localhost/HelloPHP/). You do not need to provide an alternative path to the htdocs directoy as specified in the wizard page if you are using the Apache Web Server through the Web Stack bundle. Click Finish.
Now you have created and configured a PHP project. Modify the file, index.php to read as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <?php echo "Hello Web Stack"; ?> </body> </html>
After saving the project, right click the project and click Run. A web browser window opens invoking the URL – http://localhost/HelloPHP/index.php.
You will see the Hello Web Stack page on the browser. If you get any error, check the Apache Web Server log file by clicking Applications > Developer Tools > Web Stack Admin > Logs > Apache 2 Log for more information.
Since the Apache Web Server is already configured to support PHP files, you do not need to perform any other configuration apart from getting and installing the Web Stack bundle.
Tomcat Web Server
The Web Stack software comes with the Tomcat Web Server 6.0 for deploying your JSP-based web applications. Some of the examples shown later in this document highlights the usage of the Tomcat Server in the NetBeans IDE. The NetBeans IDE for the OpenSolaris OS may not come bundled with the Tomcat server as it is already available in the OpenSolaris OS through the Web Stack bundle. But still you need to let the NetBeans IDE know where your Tomcat Server installation directory is to allow NetBeans manage Tomcat’s lifecycle.
Important - NetBeans IDE version 6.5.1 or below does not recognize the Apache Tomcat Server installed through the Web Stack bundle. This issue is tracker at http://www.netbeans.org/issues/show_bug.cgi?id=156913. Hence you need to use the NetBeans IDE 6.7 or higher to add the Apache Tomcat Server in the Server list.
To configure the Apache Tomcat Server in the NetBeans IDE, perform the following tasks:
- Download and install the NetBeans IDE 6.7 from the IPS repository (If available) or download the NetBeans IDE from the product site at http://www.netbeans.org.
- Go to Services tab. Right click Servers and click Add Servers...
- From the Servers list, select Tomcat 6.0 and click Next.
- For Server Location, enter, /usr/tomcat6.
- Select Use Private Configuration Folder (Catalina Base) and provide the Catalina Base path as /var/tomcat6.
- Enter the username and password for Tomcat's manager role.
If you have not already created a user with the manager role, edit the file /var/tomcat6/conf/tomcat-users.xml as shown below:
<tomcat-users> ... <role rolename="manager"/> <role rolename="admin"/> ... <user username="admin" password="admin" roles="tomcat,manager,admin"/> </tomcat-users>
You need to edit the tomcat-users.xml file as a privileged user (Use the pfexec command).
When the Tomcat Server is successfully configured in the NetBeans IDE, the Servers node under the Services tab shows the Tomcat 6.0 entry.
Testing the Apache Tomcat Server from the NetBeans IDE
When you have successfully added the Tomcat Server to the NetBeans's Servers list, test the setup by running some sample web applications as shown below:
Start the Tomcat Server
In the OpenSolaris OS, you can start the Tomcat Server by executing the following command:
svcadm enable -s tomcat6
Important – Do not manually start the Tomcat Server, by running any other startup script including the startup.sh script bundled with the Tomcat Server. Always use the svcadm enable/disable command to start/stop the Tomcat Server.
To test if the server is running invoke the URL - http://localhost:8080/ from a browser window. You will see the Tomcat welcome page.
Now, from the NetBeans IDE, perform the following tasks:
- Click File > New Project.
- From the Categories, select Java Web > Web Application. Click Next.
- Enter TestJSP as the project name. Click Next. Do not select any entry for Add to Enterprise Application option as our project is a simple one.
- In the Server list, select Tomcat 6.0.
- Do not modify the Java EE version (Java EE 5) and the Context Path /TestJSP. Click Next.
Do not apply any framework on your application. Click Finish. Modify the index.jsp file in the project to read as follows:
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello Web Stack</h1> </body> </html>
- Right click the TestJSP project node and select Build.
- Right click the TestJSP project node and select Run.
If you get any build error, check the Tomcat log file available at /var/tomcat6/logs/catalina.out. Your error message may look like:
java.io.FileNotFoundException: /var/tomcat6/conf/Catalina/localhost/TestJSP.xml (No such file or directory)
This is a known issue. You need to deploy the TestJSP/dist/TestJSP.war file manually from the Tomcat's manager interface available at http://localhost:8080/manager.
The NetBeans IDE 6.5.1 comes bundled with a WEBrick Server, the most widely used Ruby web server. The WEBrick Server is started automatically on Rails project creation. There is a WEBrick console window that shows the output of the web server. No other manual configuration is required for the WEBrick server. For using Mongrel or any other server, update your gems by invoking Tools > Ruby gems.
For using the native Ruby platform (available from the IPS repository) instead of the built-in Ruby platform, perform the following tasks:
- Get the Ruby package. pfexec pkg install SUNWruby18 or pfexec pkg install ruby-dev
- Click Tools > Ruby Platforms.
- Click Add Platform...
- Select the path to the native ruby interpretor (/usr/ruby/1.8/bin/ruby)
Languages and Applications Support
The NetBeans IDE supports working with non-Java scripting languages like PHP, Ruby, and other such scripting languages. If you are using the NetBeans IDE in Open Solaris OS, you can work with any of these scripting languages supported by the Web Stack. This document shows you how you can use the NetBeans IDE with the language interpreters that comes with the OpenSolaris OS.
PHP is an interpreted, dynamic, web page scripting language. NetBeans IDE has support for PHP editing and debugging through an add-on component called PHP plug-in. The plug-in supports PHP5 and some of the features include:
- Formatting, folding, and bracket completion of the PHP code
- Syntax highlighting
- Combination of HTML and PHP blocks
- Code completion
- Command-line mode
- Automatic detection of configured servers (for Solaris OS)
Supported Version – Web Stack supports PHP 5.2.9
If you have the PHP configuration setup showed in the previous sections, you should be able to create new PHP projects. However to run and debug your PHP projects, you will need:
- Apache 2 - Available through Web Stack. You can use a local server or a remote server with FTP access. Typically a local web server is utilized for development and debugging, while the production environment is located on a remote web server.
- PHP engine - Available through Web Stack.
- PHP debugger - Available through a Web Stack PHP Extension (xdebug.ini). The NetBeans IDE allows you to use XDebug, but using a debugger is optional.
For using PHP and Apache2 through Web Stack, you do not need any additional configuration.
Note - PHP language interpreter is integrated into the Apache Web Server. PHP module with MySQL and PostgreSQL database support is provided for the Apache Web Server. If you need to configure PHP with Apache 2.2 worker MPM, then you need to use Apache 2.2 Web Server + PHP FastCGI.
Some PHP modules are packaged with OpenSolaris OS as extensions. Each of the modules has a respective INI file under /etc/php/5.2/conf.d directory. Some PHP extensions are enabled by default. You can edit the PHP extension specific INI file for any specific configuration changes. / For enabling debugging support in PHP, perform the following steps:
- Click Applications > Developer Tools > Web Stack Admin > Options.
- Go to PHP tab and click enable option for the PHP Debugger check box. In the PHP tab, click Advanced Configuration to open the INI file for editing.
NetBeans PHP IDE is a pre-configured NetBeans setup that only exposes the PHP support. You do not need to download any additional PHP modules. The NetBeans PHP IDE startup time is lesser than the normal NetBeans IDE. For downloading the IDE just for PHP editing, go to http://www.netbeans.org/downloads/index.html and download the PHP IDE.
Bundled PHP Extensions
Some PHP extensions are available in the OpenSolaris OS through the Web Stack software. Each of these extensions has a respective INI file under /etc/php/5.2/conf.d directory.
The list of PHP extensions available through the Web Stack software are :
APC, GD, LDAP, OpenSSL, PostgresSQL, XDebug , Bzip2, Gettext, Mcrypt, PDO, SQLite, Zlib, Curl, Iconv, Memcache, PDO MySQL, Suhosin, DTrace, IDN, Mysqli, PDO PostgreSQL, TCP Wrap, FTP, IMAP, MySQL, PDO SQLite, and Tidy.
PHP Configuration through the Web Stack UI
You can use the Web Stack UI to modify PHP settings as supported by the Apache Web Server. For invoking the GUI tool, click Applications > Developer Tools > WebStack Admin > Options.
PHP Debugger is not enabled by default. You need to click PHP Debugger check box to enable this option. NetBeans IDE supports the use of XDebug for debugging PHP projects.
The NetBeans IDE features support for an integrated development environment for building, running, testing, and debugging Ruby and Ruby on Rails (RoR) applications. NetBeans supports Ruby project types including Ruby files, RSpec specification files, and YAML files. You can configure the NetBeans IDE to use the native ruby available through the Web Stack software. The IDE also supports Rake build tool integration and gives you access to the Interactive Ruby Shell.
Supported Version – Ruby 1.8
Note – If you need to use the Gem Manager, you must have gem installed, and the IDE must have write permission to your Ruby installation directory.
The amp-dev package does not contain the Ruby interpretor. For getting the Ruby interpretor in the OpenSolaris OS, execute the following command:
$ pfexec pkg install ruby-dev
You do not need to download and install a third-party Ruby interpretor if you are using the OpenSolaris OS with the Web Stack software. The following list describes the file structure for Ruby:
- /var/ruby/1.8/gem_home contains the Ruby gems repository. Configure the GEM_HOME environment variable to point to /var/ruby/1.8/gem_home.
- /usr/ruby/1.8/bin contains the Ruby executable as well as other utility programs, and Ruby gems programs. These programs are linked from the /usr/bin directory. For example, /usr/ruby/1.8/bin/ruby is linked from /usr/bin/ruby1.8, and may be linked from /usr/bin/ruby if 1.8 is the latest version of Ruby installed on this system.
Before proceeding to use the NetBeans IDE for Ruby, set the environmental variable GEM_HOME.
For sh -> export GEM_HOME=/var/ruby/1.8/gem_home For csh -> setenv GEM_HOME /var/ruby/1.8/gem_home
To use gem, make sure you have direct access to the Internet. If your system is behind a firewall or if it uses a proxy server, set the HTTP_PROXY variable.
If you do not set the GEM_HOME environmental variable, the NetBeans IDE will not work because the available gems cannot be enumerated if you are using a native Ruby environment. For this reason you need to set GEM_HOME in order for the gem repository to be accessible from the NetBeans IDE. Also the directory referenced by GEM_HOME should be writable. So make sure you execute the following command:
$ chmod -R a+w <GEM_HOME_PATH>
Ruby on Rails (RoR)
Rails is a full-stack framework for developing database-backed web applications. Ruby Gems is the standard Ruby package manager. You can install Rails and its dependencies executing the following command:
$ pfexec gem install rails –include-dependencies
You can also install Rails directly from the NetBeans IDE rather than invoking the gem command through command line. The Ruby on Rails environment is now set up successfully. You can now use the NetBeans IDE to create a Ruby on Rails project. When you create a project, the IDE creates the same folders and files that a rails command would create.
Note - Depending on the version of the Web Stack software, Rails may not be available automatically. If Rails is not available, you need to install that using the gem command as shown earlier in this section.
Getting Additional Ruby Gems
Ruby Gems is a system for managing Ruby software libraries. Ruby code packaged in this manner is called a gem. Gems allows downloading, installing, and managing your Ruby libraries. The Web Stack bundle in Solaris does not include a lot of bundled gems as you can use Ruby Gems to download and install additional gems. You can use the NetBeans interface for managing Gems.
You can manage Ruby gems directly from the NetBeans IDE as shown below:
- Click Tools > Ruby Gems.
- Go to New Gems tab.
- Click Reload Gems.
- Select the Ruby Gem and click Install.
Ruby and Rails support has been well documented in NetBeans site. If you are going to use your NetBeans IDE just for Ruby development, you have the option to download the IDE with only the Ruby support:
$ pfexec pkg install netbeans-ruby
For creating a Rails application perform the following steps:
- Click File > New Project.
- Under Ruby category, select Ruby on Rails Application. Click Next.
- At this point you will be prompted to select a Ruby interpreter for your project. You can select the optimized native Ruby interpreter if you have added the native Ruby interpretor as a platform as shown in the previous sections.
Getting help is always easier for the NetBeans IDE and the OpenSolaris OS. If you have a particular problem that you are facing with Web Stack, you can get help from the community mailing lists at http://forums.sun.com/forum.jspa?forumID=980&start=0.
When you have a particular issue with the NetBeans IDE, you can write to the NetBeans mailing list. To subscribe, unsubscribe, browse archives, or for more info on individual lists, please follow the appropriate links given in the NetBeans mailing list site at http://www.netbeans.org/community/lists/
Web Stack documentation is available at Web Stack Documentation. For information on the OpenSolaris OS for web development, read the Web Stack Getting Started Guide available at http://wikis.sun.com/download/attachments/48125322/WSGSG-OS.pdf. For any other issues pertaining to Web Stack documentation, send a mail to firstname.lastname@example.org.