How to Install WildFly (JBoss) on Ubuntu 18.04

Updated 

7 min read

WildFly, formerly known as JBoss is a cross-platform open source application runtime written in Java that helps you build amazing applications. WildFly is flexible, lightweight, and it is based on pluggable subsystems that can be added or removed as needed.

This tutorial will show you how to install WildFly application server on Ubuntu 18.04. The same instructions apply for Ubuntu 16.04 and any Ubuntu-based distribution, including Kubuntu, Linux Mint and Elementary OS.

Prerequisites

In order to be able to install packages on your Ubuntu system, you must be logged in as a user with sudo privileges.

Step 1: Install Java OpenJDK

WildFly requires Java to be installed. We’ll install OpenJDK, which is the default Java development and runtime in Ubuntu 18.04.

The installation of Java is pretty simple. Start by updating the package index:

sudo apt update

Install the OpenJDK package by running:

sudo apt install default-jdk

Step 2: Create a User

We will create a new system user and group named wildfly with home directory /opt/wildfly that will run the WildFly service:

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

Step 3: Install WildFly

At the time of writing, the latest version of WildFly is 16.0.0. Before continuing with the next step you should check the download page for a new version. If there is a new version replace the WILDFLY_VERSION variable in the command below.

Download the WildFly archive in the /tmp directory using the following wget command:

WILDFLY_VERSION=16.0.0.Final
wget https://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz -P /tmp

Once the download is completed, extract the tar.gz file and move it to the /opt directory:

sudo tar xf /tmp/wildfly-$WILDFLY_VERSION.tar.gz -C /opt/

Create a symbolic link wildfly which will point to the WildFly installation directory:

sudo ln -s /opt/wildfly-$WILDFLY_VERSION /opt/wildfly

WildFly will run under the wildfly user which needs to have access to the WildFly installation directory.

The following command will change the directory ownership to user and group wildfly:

sudo chown -RH wildfly: /opt/wildfly

Step 4: Configure Systemd

The WildFly package includes files necessary to run WildFly as a service.

Start by creating a directory which will hold the WildFly configuration file:

sudo mkdir -p /etc/wildfly

Copy the configuration file to the /etc/wildfly directory:

sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/

This file allows you to specify the WildFly mode and bind address. By default, WildFly will run in a standalone mode and will listen on all interfaces. You can edit the file according to your needs.

/etc/wildfly/wildfly.conf
# 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

Next copy the WildFly launch.sh script to the /opt/wildfly/bin/ directory:

sudo cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/

The scripts inside bin directory must have executable flag:

sudo sh -c 'chmod +x /opt/wildfly/bin/*.sh'

The last step is to copy the systemd unit file named to the /etc/systemd/system/ directory:

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

Notify systemd that we created a new unit file:

sudo systemctl daemon-reload

Start the WildFly service by executing:

sudo systemctl start wildfly

Check the service status with the following command:

sudo systemctl status wildfly
* wildfly.service - The WildFly Application Server
   Loaded: loaded (/etc/systemd/system/wildfly.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-02-17 04:59:39 PST; 2s ago
 Main PID: 10005 (launch.sh)
    Tasks: 62 (limit: 2319)
   CGroup: /system.slice/wildfly.service

Enable the service to be automatically started at boot time:

sudo systemctl enable wildfly

Step 5: Adjust the Firewall

If your server is protected by a firewall and you want to access WildFly interface from the outside of your local network you need to open port 8080.

To allow traffic on port 8080 type the following command:

sudo ufw allow 8080/tcp
When running a WildFly application in a production environment most likely you will have a load balancer or reverse proxy and it’s a best practice to restrict access to port 8080 only to your internal network.

Step 6: Configure WildFly Authentication

Now that WildFly is installed and running the next step is to create a user who will be able to connect using the administration console or remotely using the CLI.

To add a new user use the add-user.sh script that is located the WildFly’s bin directory:

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

You’ll be asked what type of user do you wish to add:

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

Select a and hit Enter:

Next, the script will prompt you to enter the details of the new user:

Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : linuxize
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 : 
Re-enter Password : 
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: 
About to add user 'linuxize' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'linuxize' to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'linuxize' to file '/opt/wildfly-16.0.0.Final/domain/configuration/mgmt-users.properties'
Added user 'linuxize' with groups  to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-groups.properties'
Added user 'linuxize' with groups  to file '/opt/wildfly-16.0.0.Final/domain/configuration/mgmt-groups.properties'
Is this new user going to be used for one AS process to connect to another AS process? 
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition <secret value="UGFuMjNkZWo3NyNA" />

The new user will be added to the properties files used for authentication.

Step 6: Test the WildFly Installation

To access the default WildFly page, open your browser and type: http://<your_domain_or_IP_address>:8080

Assuming the installation is successful, a screen similar to the following will appear:

Step 7: Access WildFly Administration Console

Command-Line Interface

To access the WildFly Administration Console from the command line you can use the jboss-cli.sh script.

Navigate to the WildFly’s bin directory and run the script with the --connect option:

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

You will be asked to enter your administrative username and password (created in step 6):

Authenticating against security realm: ManagementRealm
Username: linuxize
Password:

Once you login the console prompt will change to [standalone@localhost:9990 /]. Type help to get a list of commands and command syntax.

From here you can deploy and undeploy your applications, manage users and groups and configure and monitor WildFly server.

Web Interface

If you prefer to manage your server from the GUI, WildFly also provides a web-based console.

By default, the WildFly administration console is available only from localhost at http://localhost:9990/console. Sign in using the user you have created in step 6.

If you want to access the console from remote locations you’ll need to make small modifications to the wildfly.service, wildfly.conf and launch.sh files.

Open the wildfly.conf and append WILDFLY_CONSOLE_BIND=0.0.0.0 at the end of the file.

/etc/wildfly/wildfly.conf
# 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

# The address console to bind to
WILDFLY_CONSOLE_BIND=0.0.0.0

Open the launch.sh and edit the highlighted lines:

/opt/wildfly/bin/launch.sh
#!/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

Restart the service for changes to take effect:

sudo systemctl restart wildfly

Open the wildfly.service and edit the highlighted lines:

/etc/systemd/system/wildfly.service
[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

Create the /var/run/wildfly directory and set correct permissions:

sudo mkdir /var/run/wildfly/
sudo chown wildfly: /var/run/wildfly/

Notify systemd that the unit file was changed:

sudo systemctl daemon-reload

Restart the WildFly service by executing:

sudo systemctl restart wildfly

Assuming that port 9990 is not blocked in your firewall, you should be able to access the WildFly administration console at http://<your_domain_or_IP_address>:9990/console.

Conclusion

You have successfully installed WildFly on your Ubuntu 18.04 system. You can now visit the official WildFly Documentation and learn more about the WildFly features.

If you hit a problem or have feedback, leave a comment below.