Java, Glassfish, and MySQL installation in Debian for Java web application

We will create an environment for the Java web application deployment. Web server will be Glassfish 4.1 and database will be MySQL that requires to install phpMyadmin. We will configure these in a Debian(wheezy) Linux server.

First of all you need to buy a virtual server. There are lot of places where you can buy the server space e.g HostGator, Rockspace, LeaseWeb, OVH, SoftLayer.

Ideal configuration for a standard java based web application hosting in Debian Linux is,

  • Debian GNU/Linux 7.6 (wheezy)
  • CPU: 2.0 GHz
  • RAM: 4GB
  • Hard disk: 100GB

These will cost around $50 / month. When applying for the server make sure that it has MySQL database included.  after registering to the virtual server, they will provide you

  • A control panel where you can see your configuration.
  • Username password for the control panel.
  • one or more real ip addresses
  • Root password for the Debian OS

After login in to the control panel, there you can get the Debian Linux configuration and root password. If you don’t have root password in the control panel, ask for it where you  have bought this server.

 

Login to the Debian

  • Identify the IP address. It should be in your registration confirmation page. also you can have it in the control panel.
  • Download and install PuTTY.
  • Add IP address and choose SSH for the connection type.

putty

  • It will prompt for user name and password. enter user name “root” and your password for the root user.

debina login

Now you are into your virtual server command prompt.

 

Java installation

1. Use the following command to download the jdk bundle.  Go to Oracle site and start downloading the 64bit bundle to get the bundle. When I am writing this article the bundle name is jdk-8u5-linux-x64.tar.gz. Replace the exact bundle name in the command below.

#wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz

Exception: Do not download 32bit version, it will not work in your 64bit OS or vise-versa. to check the OS version, type comman uname –m.

2. Extract the jdk bundle to the folder /opt/jdk . you need to create the folder first.

#mkdir /opt/jdk
#tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk

3. Integrate your JVM with the OS. Use the following commands.

#update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100
#update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100

4. You are all set. Check the Java version with

#java –version

 

Configure MySQL

Your Debian is shipped with MySQL. You need to configure it.

1. Add a password for the root user.

#mysql
mysql> UPDATE mysql.user SET Password=PASSWORD('NewPass') WHERE User='root';
mysql> FLUSH PRIVILEGES;

‘NewPass’ is any password you want for your future use.

Exception: Do not ignore the FlLUSH PRIVILEGES comman.

if you Debian does not shipped with MySQL, install it with the following command

apt-get update
apt-get dist-upgrade

apt-get install mysql-server mysql-client

You are all set with configuring yoru MySQL server.

 

Install phpMyAdmin

1. Install phpmyadmin and it will install its required dependencies e.g. PHP, and web server Apache2

#apt-get install phpmyadmin

It will prompt for MySQL root password. Also it will ask for web server selection, choose Apache2

 

2. Login to the phpmyadmin.

Start your browser and type the url,

http:\\[your server ip address]\phpmyadmin

Login with the mysql root username and password.

You are all set with configuring phpMyAdmin.

 

Install Glassfish server

1. Download Glassfish using the following link. To get the exact bundle name go and try download the latest bundle from Oracle site . Lets install the glassfish server in /opt folder.

#cd /opt
#wget http://dlc.sun.com.edgesuite.net/glassfish/4.1/release/glassfish-4.1.zip
[code]
[code language="bash"]
#unzip glassfish-4.1.zip
#cd /opt/glassfish4/glassfish/bin
nano /etc/init.d/glassfish

Put the following code

#! /bin/sh

GLASSFISH=/opt/glassfish4/glassfish/bin

case "$1" in
start)
echo "starting glassfish.."
$GLASSFISH/asadmin start-domain domain1
;;
restart)
$0 stop
$0 start
;;
stop)
echo "stopping glassfish.."
$GLASSFISH/asadmin stop-domain domain1
;;
*)
echo $"Switches..: $0 {start|stop|restart}"
exit 3
;;
esac
:
chmod a+x /etc/init.d/glassfish
update-rc.d glassfish defaults

To Start, stop or restart glassfish, use the following command.

service glassfish start
service glassfish stop
service glassfish restart
asadmin> change-admin-password --user admin

Enter admin password> [BLANK]
Enter new admin password>NewPass
Enter new admin password again>NewPass

Exception: Keep the first step blank, just hit enter.

 

2. Make the Glassfish console admin panel secure.

#cd /opt/glassfish4/glassfish/bin
#./asadmin --host 56.56.67.67 --port 4848 enable-secure-admin

use this command otherwise you can not login to the admin console UI.
56.56.67.67 is an example IP address here.

 

3. Sign in to the glassfish admin panel.

Start your browser and visit to the url,

https://[your server ip address]:4848

4848 port is the default port for glassfish admin panel. You are all set with installing glassfish server. Now you can deploy your Java application installer war file to this glassfish server.

My default the server port will be 8080. After installing your application, the url will be,

http://[your server ip address]:8080/[your app context root name]

 

If you want to remove the port number from the url, you have change the port number to 80. But remember that your Apache2 web server for your phpMyadmin is using 80 port. You have to change the port number of Apache2 to something, may be 81, and then change the glassfish server port from 8080 to 80.

Leave a Comment