How to Setup an Openfire XMPP Server on Ubuntu 16.04 LTS

Published on: Fri, May 11, 2018 at 11:32 am EST
Linux Guides Server Apps Ubuntu

Openfire is a free and open source XMPP server which is being widely deployed in enterprises and organizations to deliver real time collaborations.

In this article, I will guide you through installing Openfire on a Ubuntu 16.04 LTS x64 server instance.

Prerequisites

  • A fresh Vultr Ubuntu 16.04 LTS x64 server instance. Say its IP address is 203.0.113.1.
  • A sudo user.
  • The server instance has been updated to the latest stable status using apt.
  • The server instance's hostname, domain name, and FQDN have been setup as openfire, example.com and openfire.example.com, respectively.

Install OpenJDK 8 Java Runtime Environment

As a Java applet, Openfire requires Java Runtime Environment 1.7 or later. Install OpenJDK 8 Java Runtime Environment openjdk-8-jre as follows:

sudo apt install openjdk-8-jre -y

Having OpenJDK 8 JRE installed, use the command below to confirm the result:

java -version

The output will resemble the following:

openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

Finally, you need to setup the JAVA_HOME environment variable:

echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | sudo tee -a /etc/profile
source /etc/profile

Download and install the latest Openfire Debian package

On the official Openfire download page, find the direct download URL pointing to the latest stable release of the Openfire Debian package.

Next, download and rename the Openfire 4.2.2 Debian package:

cd
wget -O openfire_4.2.2_all.deb https://www.igniterealtime.org/downloadServlet?filename=openfire/openfire_4.2.2_all.deb

Install Openfire:

sudo apt install ~/openfire_4.2.2_all.deb -y

Openfire will be installed in the /var/lib/openfire directory.

Finally, start the Openfire service and make it automatically start on boot:

sudo systemctl start openfire.service
sudo systemctl enable openfire.service

Setup an external MariaDB database for Openfire

Openfire can work with an embedded database or an external database. In order to achieve better performance, you can setup an external database as described in this step. If the embedded database is OK with you, skip this step.

Install the latest stable release of MariaDB:

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo apt install mariadb-server mariadb-client -y

Note: During the installation process, you will be prompted to input a new password for the MariaDB root user several times. Since we will setup this password later, just skip these prompts for now.

Start the MariaDB service and make it automatically start on boot:

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Secure the installation of MariaDB:

sudo /usr/bin/mysql_secure_installation

When prompted, answer the questions as follows:

  • Enter current password for root (enter for none): Just press ENTER
  • Set root password? [Y/n]: Y
  • New password: your-MariaDB-root-password
  • Re-enter new password: your-MariaDB-root-password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]: Y
  • Reload privilege tables now? [Y/n]: Y

Create a dedicated database for Openfire using the MySQL shell:

mysql -u root -p

In the MySQL shell, use the following commands to create a database, openfire, a database user, openfireuser, and its password, yourpassword:

CREATE DATABASE openfire;
CREATE USER 'openfireuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON openfire.* TO 'openfireuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Setup the Openfire XMPP server

Before you can setup the Openfire XMPP server on its web interface, you need to open the port 9090 by modifying firewall rules:

sudo ufw allow 9090
sudo ufw enable

Next, point your browser to http://203.0.113.1:9090 to start the setup process.

On the "Welcome to Setup" page, choose your language and then click the "Continue" button.

On the "Server Settings" page, input the XMPP domain name example.com and the server host name (FQDN) openfire.example.com, leaving other fields untouched, and then click the "Continue" button.

On the "Database Settings" page, choose the "Standard Database Connection" option and then click the "Continue" button.

On the "Database Settings - Standard Connection" page, input settings as follows, leaving other options untouched, and then click the "Continue" button.

  • Database Driver Presets: MySQL
  • JDBC Driver Class: com.mysql.jdbc.Driver
  • Database URL: jdbc:mysql://localhost:3306/openfire?rewriteBatchedStatements=true
  • Username: openfireuser
  • Password: yourpassword

On the "Profile Settings" page, choose the "Default" option, and then click the "Continue" button.

On the "Administrator Account" page, input the admin email address admin@example.com and a new password twice, and then click the "Continue" button. If you click the "Skip This Step" button, you will have to use the default password admin.

On the "Setup Complete!" page, click the "Login to the admin console" button to finish the setup and jump to the "Openfire Administration Console" login page. You should use the username admin and the new password you setup earlier to log in. Additional settings can be fine-tuned on this page.

Want to contribute ?

You could earn up to $300 by adding new articles