How to install WildFly on Ubuntu 16.04

How to install WildFly on Ubuntu 16.04

In this tutorial we are going to provide you with step by step instructions on how to install WildFly with Nginx as a reverse proxy on an Ubuntu 16.04 VPS.
WildFly is a flexible and lightweight open source application server authored by JBoss, now developed by Red Hat.
At the moment of writing this article, WildFly 10 is the latest release in a series of JBoss open-source application server offerings.

1. Update your system

Let’s start with the installation. Make sure your server OS packages are fully up-to-date:

apt-get update 
apt-get upgrade

2. Remove Apache server

Stop and remove Apache, then install nginx using the following commands:

service apache2 stop
apt-get remove apache2
apt-get autoremove
apt-get install nginx

3. Configure Nginx

Edit the default nginx configuration file:

vi /etc/nginx/sites-enabled/default

Delete the following line:

listen [::]:80 default_server;

4. Enable nginx service

Enable nginx service to start on boot and start it:

systemctl enable nginx
systemctl start nginx.service

5. Install Java

In order to run WildFly, Java has to be installed on the server so run the following command to install the Java Development Kit package (JDK):

apt-get install default-jdk

To find out what version of Java has been installed, run:

java -version

The output should be something like this:

openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

6. Create WildFly User

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

7. Download WildFly

Download the latest version of WildFly available at ‘http://wildfly.org/downloads’ to a directory on the server and extract it using the following commands:

cd /opt
wget http://download.jboss.org/wildfly/10.0.0.Final/wildfly-10.0.0.Final.tar.gz
tar -xvzf wildfly-10.0.0.Final.tar.gz
mv wildfly-10.0.0.Final wildfly

8. Configure WildFly

Create a wildfly configuration file:

vi /etc/default/wildfly

Add the following lines to it:

WILDFLY_USER="wildfly"
STARTUP_WAIT=180
SHUTDOWN_WAIT=30
WILDFLY_CONFIG=standalone.xml
WILDFLY_MODE=standalone
WILDFLY_BIND=0.0.0.0

so it will start WildFly 10 using the default web profile configuration in ‘standalone’ mode.
Create a WildFly startup script, named ‘launch.sh’:

vi /opt/wildfly/bin/launch.sh
#!/bin/sh

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

if [ "x$1" = "xdomain" ]; then
    echo 'Starting Wildfly in domain mode.'
    $WILDFLY_HOME/bin/domain.sh -c $2 -b $3
else
    echo 'Starting Wildfly in standalone mode.'
    $WILDFLY_HOME/bin/standalone.sh -c $2 -b $3
fi

Make the startup script executable:

chmod 755 /opt/wildfly/bin/launch.sh

WildFly can be started using the launch.sh script we created in the /opt/wildfly/bin directory or even better, we will create a systemd init file for that purpose:

vi /etc/systemd/system/wildfly.service
[Unit]
Description=The WildFly Application Server
After=syslog.target network.target
Before=nginx.service

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

[Install]
WantedBy=multi-user.target

Set the proper ownership of files and directories located to the /opt/wildfly directory:

chown wildfly:wildfly -R /opt/wildfly/

Start the WildFly service and enable WildFly to start on boot:

systemctl daemon-reload
systemctl start wildfly
systemctl enable wildfly

9. Create a new nginx block

Create a new nginx block so you can access the WildFly management interface using nginx as a reverse proxy:

vi /etc/nginx/sites-available/wildfly

Add the following lines:

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
upstream wildfly {
    server 127.0.0.1:8080;
}

server {
    listen      80;
    server_name your-domain.com;

    access_log  /var/log/nginx/wildfly.access.log;
    error_log   /var/log/nginx/wildfly.error.log;

    proxy_buffers 16 64k;
    proxy_buffer_size 128k;

location / {
        proxy_pass  http://wildfly;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;

        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto https;
    }

}

Do not forget to replace ‘your-domain.com’ with your actual domain name.

ln -s /etc/nginx/sites-available/wildfly /etc/nginx/sites-enabled/

Restart nginx for the changes to take effect:

systemctl restart nginx.service

10. Add new user

In order to access the WildFly management console, you need to add a new user. Execute the add-user.sh script within the bin directory of the WildFly installation and enter the requested information:

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

That is it. The WildFly installation is now complete.

To access the WildFly management console, open http://your-domain.com using the newly created user login credentials.
wildfly management console

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

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

14 thoughts on “How to install WildFly on Ubuntu 16.04”

  1. Hello,
    Thanks for this tutorial. Installation goes good. The wildfly is started, but after clicking Administration Console i have message – the site can’t be reach – refused to connect. So it is probably some problem with my vps. Any idea?

    Reply
  2. I see the same issue trying to reach the admin console. The port 80 brings up the Wildfly home – navigating to the admin console redirects to port 9990 /console http: //your-domain.com:9990/console – unable to connect

    Reply
    • The location block “/” will match all requests starting with “/”, such as yourdomain.com/, yourdomain/other_ulr/ ..etc.

      Reply
  3. Is there any difference if creates symbolic link instead of moving /opt/wildfly-10 to /opt/wildfly?
    ln -s wildfly-13.0.0.Final/ wildfly

    Reply
    • How do i add please, i tried

      ….

      server {
      listen 80;
      server_name my-site.com;
      server_name www.my-site.com;

      ….

      }

      and it is still not working

      Reply
      • You should add your domain name (with and without www) in one line. Also, you should not include information about protocol, like http://

        Reply

Leave a Comment