Install Glassfish 4 on a Debian 8 VPS

glassfishIn this article we will cover the steps needed for installing a fully functional Glassfish server on a Linux VPS, specifically a Debian 8 VPS.
GlassFish is a free open source application server for the Java EE platform. With this application the developers can develop and deploy portable and scalable enterprise Java applications.

This guide should work on other Debian systems as well but was tested and written for a Debian 8 (Jessie) OS.

Login to your server via SSH

ssh root@server_ip

Let’s reassure that we have the proper version of Debian installed on our server :

# lsb_release -a
Distributor ID: Debian
Description: Debian GNU/Linux 8.1 (jessie)
Release: 8.1
Codename: jessie

REQUIREMENTS

We will be using our SSD 1 Linux VPS Hosting plan for this tutorial.

UPDATE THE SYSTEM

Make sure your server is fully up to date. Also, install wget and unzip:

# apt-get update && apt-get upgrade

# apt-get install unzip wget

INSTALL ORACLE JAVA 8

Your first step is to add the webupd8team Java PPA repository in your Debian system. Then you will be able to install Oracle Java 8. Issue the following commands:

# echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list

# echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list

# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886

Update the package index and install Java 8:

# apt-get update

# apt-get install oracle-java8-installer

Check if Java has been properly installed:

# java -version

You should receive the following output:

java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

INSTALL GLASSFISH

We will now download and install Glassfish into the /opt directory. When this tutorial was written the latest Glassfish version was 4.1. Then we will create a user that will start the service because running Glassfish under root is not recommended.

The below commands will complete the above mentioned procedure:

# cd /opt

# wget http://download.java.net/glassfish/4.1/release/glassfish-4.1-web.zip

# unzip glassfish-4.1-web.zip

# useradd glassfish

# chown -R glassfish:glassfish /opt/glassfish4

You would want to ease the starting/stopping/restarting of your Glassfish server. Therefore, let’s create an init script. We will create a ‘glassfish’ file in the ‘/etc/init.d’ directory:

# vim /etc/init.d/glassfish

Paste the following lines:

#!/bin/bash
#
# description: Startup script for Glassfish Application Server
# processname: glassfish

GLASSFISH_HOME=/opt/glassfish4/
export GLASSFISH_HOME
GLASSFISH_USER=glassfish
export GLASSFISH_USER

start() {
echo -n "Starting Glassfish: "
su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
sleep 2
echo "done"
}

stop() {
echo -n "Stopping Glassfish: "
su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
echo "done"
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: glassfish {start|stop|restart}"
exit
esac

Make the script executable:

# chmod a+x /etc/init.d/glassfish

Make the Glassfish server to start on boot up:

# update-rc.d glassfish defaults

You can now start Glassfish:

# /etc/init.d/glassfish start

The default GlassFish port numbers are:

Administration: http://your_server_ip:4848
HTTP listener: http://your_server_ip:8080
HTTPS listener: http://your_server_ip:8181

So, open your favorite web browser and navigate to http://your_server_ip:4848

You will be welcomed by the Glassfish administration window, but there is an ‘Secure Admin must be enabled to access the DAS remotely’ error. You can solve this by following the next steps:

Enter the bin directory:

# cd /opt/glassfish4/bin

Make the asadmin script executable:

# chmod +x asadmin

Enter the following command:

# ./asadmin --host your_server_IP --port 4848 enable-secure-admin

You will receive the below error:

remote failure: At least one admin user has an empty password, which secure admin does not permit. Use the change-admin-password command or the admin console to create non-empty passwords for admin accounts.
Command enable-secure-admin failed.

So, to solve this change the admin password:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
# ./asadmin --port 15123 change-admin-password

Enter admin user name [default: admin]> Press enter

Enter the admin password> Press enter

Enter the new admin password> Enter your new password

Enter the new admin password again> Enter the new password again

Now run this command again:

# ./asadmin --host your_server_IP --port 4848 enable-secure-admin

You will get the following output:

You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.

As the message says, you should restart Glassfish:

# /etc/init.d/glassfish restart

Refresh your browser or open http://your_server_ip:4848 with a new one and log in using the admin user and password you’ve just configured.

Congratulations, you have successfully installed Glassfish 4.1 on your Debian 8 VPS.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Glassfish for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

5 thoughts on “Install Glassfish 4 on a Debian 8 VPS”

Leave a Comment