Easy deploy your web apps with Sun GlassFish Web Stack
By Kai Seidler on Oct 14, 2009
Today I want to show you a quick installation walkthrough of Sun GlassFish Web Stack. I'm using Solaris 10 in this walkthrough, but installation on RHEL is absolutely the same. As a small deployment example for a web application I'll do an installation of WordPress.
Web Stack Installation
Okay, first step: Get the Sun GlassFish Web Stack.
Simply enter http://sun.com/webstack in your browser.
After clicking on the Get It button, you're asked to pick your platform: Red Hat Enterprise Linux or Solaris 10. (You may wonder why there is no OpenSolias download, that's quite simple: because the Web Stack is already sipped with OpenSolaris (2009.06), all you need to do to install the main components is to do a pkg install amp. And you'll get the Apache, MySQL and PHP components of Web Stack installed right on your system.)
After picking the platform, you need to decide which kind of distribution you want to download: native packages or the IPS-based distribution:
The native packaging distribution (aka RPM/SVR4) differs two version: one including Java-based components like Tomcat, GlassFish and Hudson, and one without.
For this demo I picked my personal favorite, the IPS-based distribution, because it allows me a non-root install and gives me the ability to place my Web Stack anywhere I want in the directory tree of my system. So I don't need to have root access and can install Web Stack as a regular user.
After the download is finished I open a terminal and take a look at my system environment:
[oswald@localhost ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 7.2G 2.3G 4.5G 34% / /dev/hda1 99M 12M 83M 13% /boot tmpfs 125M 0 125M 0% /dev/shm [oswald@localhost ~]$ pwd /home/oswald [oswald@localhost ~]$ id uid=500(oswald) gid=500(oswald) groups=500(oswald) [oswald@localhost ~]$ ls -l total 14452 -rw-r--r-- 1 oswald 14765264 Oct 12 14:43 webstack-image-1.5-b09-redhat-i586.zip
My current working directory is my home directory. There is enough space left on my file system. I'm a non-root, regular user, and I see the downloaded IPS installer image.
Now I'm unzipping the image to my home directory:
[oswald@localhost ~]$ unzip -q webstack-image-1.5-b09-redhat-i586.zip
This creates a directory named webstack1.5 by default. You can rename it to anything you want or simply keep the default name. In this case I choose to name it demo:
[oswald@localhost ~]$ mv webstack1.5 demo
Now I change into that directory and start the Update Tool:
[oswald@localhost ~]$ cd demo [oswald@localhost demo]$ bin/updatetool
So, what we're seeing here is the update tool. Our current Sun GlassFish Web Stack installation is highlighted on the left hand side. If you have other products installed or multiple Web Stack installs, all these images will show up too. In this case I've only one image and once I click on Available Add-ons.
Now I pick all the components I want to use in this demo, so I select Apache HTTP server, MySQL server, PHP Server and the PHP MySQL connector. By the way, if I realize I need more packages later on, I can come back here anytime and install whatever I need. For now, I've selected all I want at this point, and all I have to do now is to press the beautiful green install button above the package list.
After downloading, I get back to the shell and use the command line tool pkg to review the list of installed packages:
oswald@localhost demo]$ bin/pkg list NAME (PUBLISHER) VERSION STATE UFIX pkg 1.111.3-30.2210 installed ---- pkg-toolkit-incorporation 2.2.1-30.2210 installed ---- python2.4-minimal 22.214.171.124-30.2210 installed ---- sun-apache22 2.2.11-1.5 installed ---- sun-mysql51 5.1.30-1.5 installed ---- sun-mysql51lib 5.1.30-1.5 installed ---- sun-php52 5.2.9-1.5 installed ---- sun-php52-mysql 5.2.9-1.5 installed ---- sun-wsbase 1.5-1.5 installed ---- updatetool 2.2.1-30.2210 installed ---- wxpython2.8-minimal 2.8.8-30.2210 installed ----
You can also use pkg to install components, like in the Update Tool. So for the terminal addicted: if you don't like a GUI, there is also a command-line alternative.
Okay, let's go on. I now start the Apache web server:
[oswald@localhost demo]$ bin/sun-apache22 start Starting apache22
And to check if the Apache is really running and working I'll take my browser to http://localhost. But wait a second...
As we probably all know, by default, the Apache web server runs on port 80, which is the default port on which most Web servers run. But in the Unix world all port numbers below 1024 require root permissions to bind. And since I started Apache as a normal non-root user, the Apache will be unable to bind to port 80.
If you use Web Stack as non-root user, Web Stack will add 10000 to every port number below 1024. So in this case Apache will use 10080 as it's favorite port.
At http://localhost:10080/ we find the welcome page of Sun GlassFish Web Stack:
But what's life with just an Apache, let's also start the MySQL and let the database server join our team:
[oswald@localhost demo]$ bin/sun-mysql51 start Starting mysql51
- Because everyone on my system and on my network can now access my MySQL server, I strongly need to secure my installation by setting a password for MySQL's root user:
[oswald@localhost demo]$ mysql/5.1/bin/mysqladmin -u root password "demo"
Okay, demo is probably not a secure password for a production environment, but for this demo purposes it's a very appropriate one.
That's all. Your AMP stack is now ready.
As an example I will now install the famous blogging software WordPress within my new AMP stack. Not because it's so difficult to do, but it's a good and pragmatic way to show the AMP stack is working and out-of-the-box capable to run popular web applications.
First I need to create a database and a user for WordPress to access the database and to store its data.
Okay, that should be an everyday task for a MySQL DBA:
[oswald@localhost demo]$ bin/mysql -uroot -pdemo Welcome to the MySQL monitor. Commands end with ; or \\g. Your MySQL connection id is 2 Server version: 5.1.30-log Source distribution Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer. mysql> CREATE DATABASE wordpress; Query OK, 1 row affected (0.01 sec) mysql> GRANT ALL PRIVILEGES ON wordpress.\* TO 'wordpress'@'localhost' \\ IDENTIFIED BY 'demo'; Query OK, 0 rows affected (0.98 sec) mysql> QUIT
Get into the MySQL monitor, aka the MySQL command line tool, to connect to the database server. I use the CREATE DATABASE statement to create a database named wordpress. And with the GRANT statement I create a user named wordpress identified by the password demo. Again this is probably not a good password for production use, but for a demo this is perfecto.
- After changing into Apache's document root directory I wget the latest wordpress version:
[oswald@localhost demo]$ cd var/apache2/2.2/htdocs [oswald@localhost htdocs] wget -q http://wordpress.org/latest.tar.gz
With GNU tar I extract the archive:
[oswald@localhost htdocs]$ /usr/sfw/bin/tar xfz wordpress-2.8.4.tar.gz
This creates a directory called wordpress.
Now I can access my WordPress installation by pointing my browser to http://localhost:10080/wordpress.
From now on it's very easy. Simply enter the details for the database server connection:
The database name: wordpress.
The user name: wordpress.
The password: demo.
The database host: localhost.
And the table prefix wp_.
And on the next page:
I choose a name for my blog, and enter my email address. Press Install WordPress. And now it only takes a few moments and the installation is done. (Write down your random admin password, you will probably need it later.)
Now I want to check if the Wordpress installation was successful and again point my browser to http://localhost:10080/wordpress.
And, voilà, there it is: my shiny new "Sun GlassFish Web Stack" blog. Hooray.
That's all. Welcome to the wonderful world of AMP.