Install and Configure WildFly (JBoss) App Server on Ubuntu 16.04 | 18.04

WildFly (formally JBoss) is a lightweight, fast and highly optimized Java based application runtime that allows you to develop great applications from a single IDE.

This brief tutorial shows students and new users how to install and configure WildFly on Ubuntu 16.04 | 18.04 LTS servers.

WildFly is cross-platform with robust dashboard which makes changing a setting in the application server, configuration very simple and quick. No need to browse unnecessary pages to customize your environment to fit you needs.

For more about WildFly and other related documentation, please visit its homepage.When you’re ready to setup WildFly on Ubuntu, follow the steps below:

Step 1: Install OpenJDK

WildFly is written in Java and require Java JDK to function. you either install the official Oracle Java JDK or use the open source alternative called OpenJDK.

For this tutorial, we’re going to be installing the open source version of Java.

To do that, run the commands below:

sudo apt update
sudo apt install default-jdk

After installing OpenJDK above, you can run the commands below to validate that it is installed.

java -version

You should see similar lines as below:

openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)

If you see the lines above, then Java is installed and ready.

Step 2: Setup WildFly User

Since this is an application server, it’s usually recommended to use a dedicated service account. Run the commands below to create WildFly service account to manage the server.

Run the commands below to create an account and group called wildfly.

sudo groupadd -r wildfly
sudo useradd -r -g wildfly -d /opt/wildfly -s /sbin/nologin wildfly

After that, continue below to downloading and configuring WildFly packages.

Step 3: Download and Configure WildFly

Now that you’ve installed Java JDK and created a service account for WildFly, run the commands below to download WildFly packages. At the time of this post, the current version is 16.0.0.Final.

You can check its download page to get the latest when they become available.

Using wget command, you can easily download it using the commands below:

cd /tmp
wget https://download.jboss.org/wildfly/16.0.0.Final/wildfly-16.0.0.Final.tar.gz

After downloading, run the commands below to create WildFly folder in the /opt directory and change its ownership to WildFly service account.

tar xvf wildfly-16.0.0.Final.tar.gz
sudo mv wildfly-16.0.0.Final/ /opt/wildfly
sudo chown -RH wildfly: /opt/wildfly

Next, create WildFly service folder in the /etc/ directory by running the commands below.

sudo mkdir -p /etc/wildfly

Then copy WildFly configuration files, executables into the newly created directory above, and make its scripts in the /etc/wildfly/bin directory executable.

sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/
sudo cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/
sudo sh -c 'chmod +x /opt/wildfly/bin/*.sh'

After that copy its systemd file to the /etc/systemd/system/ directory by running the commands below

sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/

Now you can use the commands below to stop, start and enable WildFly services to automatically start at boot time.

sudo systemctl stop wildfly.service
sudo systemctl start wildfly.service
sudo systemctl enable wildfly.service

To check its started, run the commands below:

sudo systemctl status wildfly.service

You should see its status service info as shown below:

● wildfly.service - The WildFly Application Server
   Loaded: loaded (/etc/systemd/system/wildfly.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-04-03 10:49:06 CDT; 17s ago
 Main PID: 2252 (launch.sh)
    Tasks: 109 (limit: 4683)
   CGroup: /system.slice/wildfly.service
           ├─2252 /bin/bash /opt/wildfly/bin/launch.sh standalone standalone.xml 0.0.0.0
           ├─2253 /bin/sh /opt/wildfly/bin/standalone.sh -c standalone.xml -b 0.0.0.0
           └─2336 java -D[Standalone] -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMe

Apr 03 10:49:06 ubuntu1804 systemd[1]: Started The WildFly Application Server.

Now that you’ve downloaded and configured WildFly service, run the commands below to create a user account that will connect and manage the app server web console.

sudo /opt/wildfly/bin/add-user.sh

You’ll be prompted. type a to continue.

What type of user do you wish to add? 
 a) Management User (mgmt-users.properties) 
 b) Application User (application-users.properties)
(a): a

Type in a new username and create a password:

Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : superadmin
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
 - The password should be different from the username
 - The password should not be one of the following restricted values {root, admin, administrator}
 - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
Password : 
WFLYDM0102: Password should have at least 1 non-alphanumeric symbol.
Are you sure you want to use the password entered yes/no? yes

Type yes for the other options and complete the setup.

WildFly should be installed and ready.

Open your browser and browse to the server hostname or IP address followed by port #8080 (its default port).

WildFly Ubuntu Setup

Then admin console is at:

/console

Out of the box, the server console is restricted to the local server only. If you’d like to connect from a remote location, Open it’s configuration file by running the commands below.

sudo nano /etc/wildfly/wildfly.conf

Then add the highlighted line in the file and save.

# The configuration you want to run
WILDFLY_CONFIG=standalone.xml

# The mode you want to run
WILDFLY_MODE=standalone
# The address to bind to
WILDFLY_BIND=0.0.0.0

#WildFly Console bind 
WILDFLY_CONSOLE_BIND=0.0.0.0

After that run the script below to create an account to logon to the admin console.

sh /opt/wildfly/bin/jboss-cli.sh --connect

You’ll be prompted to enter the account and password you created above.

Authenticating against security realm: ManagementRealm
Username: superadmin
Password: 
[standalone@localhost:9990 /]

Next, open the launch script

sudo nano /opt/wildfly/bin/launch.sh

And edit the highlighted lines,

#!/bin/bash

if [ "x$WILDFLY_HOME" = "x" ]; then
    WILDFLY_HOME="/opt/wildfly"
fi

if [[ "$1" == "domain" ]]; then
    $WILDFLY_HOME/bin/domain.sh -c $2 -b $3 -bmanagement $4
else
    $WILDFLY_HOME/bin/standalone.sh -c $2 -b $3 -bmanagement $4
fi

Exit and save the file.

Restart the service.

sudo systemctl restart wildfly.service

Next, open WildFly service by running the commands below.

sudo nano /etc/systemd/system/wildfly.service

Then edit the highlighted line and save.

[Unit]
Description=The WildFly Application Server
After=syslog.target network.target
Before=httpd.service

[Service]
Environment=LAUNCH_JBOSS_IN_BACKGROUND=1
EnvironmentFile=-/etc/wildfly/wildfly.conf
User=wildfly
LimitNOFILE=102642
PIDFile=/var/run/wildfly/wildfly.pid
ExecStart=/opt/wildfly/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND $WILDFLY_CONSOLE_BIND
StandardOutput=null

[Install]
WantedBy=multi-user.target

Save the file and exit.

Reload systemd and restart.

sudo systemctl daemon-reload
sudo systemctl restart wildfly.service

That’s it! You can now access the admin console remotely.

WildFly console access

Congratulations! you have successfully installed and configure WildFly (Formally JBoss) on Ubuntu 16.04 | 18.04.

You may also like the post below: