Install Ejabberd XMPP Server in Ubuntu 16.04

In this tutorial we are using the 64 bit deb package

Step 1: Download ejabberd

Download the deb package from https://www.process-one.net/en/ejabberd/downloads/

OR alternatively, use wget to download

wget https://www.process-one.net/downloads/downloads-action.php?file=/ejabberd/17.01/ejabberd_17.01-0_amd64.deb

Now rename the package as follows:

mv downloads-action.php?file=%2Fejabberd%2F17.01%2Fejabberd_17.01-0_amd64.deb ejabberd_17.01-0_amd64.deb

Step 2: Backup ejabberd

If you are doing a fresh install, you can jump to Step 3. If you are upgrading ejabberd, take a backup of your database using the following command:

/opt/ejabberd-xx.xx/bin/ejabberdctl backup ejabberd.backup

where xx.xx is your current ejabberd version.

  • Make a copy of the backup file and the conf folder. They will be located in /opt/ejabberd-xx.xx/database/ and /opt/ejabberd-xx.xx/conf respectively.
  • Stop ejabberd node

When upgrading, also check the upgrade process from https://docs.ejabberd.im/admin/upgrade/
Note: Make sure you have the necessary backups before installing the new version.

Step 3: Install ejabberd

Install ejabberd using the following command:

dpkg -i ejabberd_17.01-0_amd64.deb

Ejabberd will be installed in the /opt folder, so change your directory to this folder.

cd /opt/ejabberd-17.01

To check if installation was successful, you should have the following folders
bin, conf, database, doc, lib and logs.

Step 4: Installing SSL Certificates

If you are using a server for production, you will need to install SSL certificates.

  • Generating a Certificate Signing Request with key. This will generate two files, the csr file and the server key. Using openssl command, you can generate the two files. This will prompt you to enter information that will be incorporated into your certificate request.
    openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr
  • Submit your CSR file to a any CA. You use any CA for this.
  • After you receive the certificates from your CA, you need to create a pem file for ejabberd. You will have to follow concatenate according to the following order:
    1. Your private key file
    2. Your domain certificate
    3. The root certificate

    We do this using cat command as follows, in the order mentioned above:

    cat server.key >> server.pem
    cat yourdomain_ca.crt >> server.pem
    cat root.crt >> server.pem
    
  • Copy the server.pem file to ejabberd conf folder

Step 5: Edit the configuaration file

Configure your server using a text editor. Some of the configurations are pre-configured, however you will need to make some changes which are relevant to your requirements.

Lets configure our server:

vi /opt/ejabberd-17.01/conf/ejabberd.yml

a) Configure hosts (domain names served by ejabberd not to be confused with the ejabberd node name)
hosts:

...
  - "yourhostname"
...

b) Configure your admin user, For e.g, In the ACL section, you configure your admin user

...
admin:
  user:
    - "admin@yourhostname"
...

For a complete list of configurations, check the documentation at https://docs.ejabberd.im/admin/configuration/

Step 6: Start the server

Start ejabberd using the following command:

/opt/ejabberd-17.01/bin/ejabberdctl start

You can check the status of ejabberd using the following command:

/opt/ejabberd-17.01/bin/ejabberdctl/ejabberdctl status

Step 7: Add users

Now that you have configured your server, you will need to add some users to the server.
For e.g, we will create the admin user, using the following command:

/opt/ejabberd-17.01/bin/ejabberdctl register admin yourhostname adminpassword

replacing yourhostname and adminpassword with yours

Step 8: Open web console

Open web admin console in browser
http://yourip:5280/admin/
or
https://yourip:5281/admin/

Note: For https you will also need to configure the listener in the configuration file.

Enter your credentials using username admin@yourhostname and the password you entered while creating the admin user

If everything went fine, you should see the web console. If your server does not start you can check the logs in the log folder within the ejabberd installation folder.

You can use the following command to check if you have any errors while starting the server.

ejabberdctl debug

P.S:
If you opt for a different database other than mnesia
Follow the steps in https://docs.ejabberd.im/admin/guide/databases/mysql/

A note on XMPP communications protocol

    When it comes to messaging, I’ve been interested to know how messaging protocols work such as XMPP (Extensible Messaging and Presence Protocol) communications protocol, which is an open standard for messaging that provides a set of protocols for message exchange based on XML. Applications such as WhatsApp, GoogleTalk and Facebook external chat API to name a few, uses the XMPP protocol (or a customized version of the protocol). While the standards are open, these protocols themselves are complicated and heavyweight with a lot of overhead because of the extensive use of XML. Some application servers such as Ejabberd, Openfire, Tigase, Prosody have implemented these protocols for messaging. Based on the protocols (XEPs) implemented by these XMPP servers, client software/ IM applications can use these protocols for connecting with the servers. You can compare the list of messaging protocols here. When choosing a protocol, many factors come into play. But since more of the messaging happens in real-time, we want to minimize overhead and maintain a steady connection. Scalability, concurrency and reliability plays important roles. Due to this, some of the applications such as GTalk has moved on and replaced by Google Hangouts which uses its own protocols for messaging. However, it is interesting to learn how these protocols work providing insights in handling messages, presence, roster, group sharing, etc. We also have a list of client software and libraries which we can use to connect to the XMPP server. In the next series of posts, I will walk through setting up your own XMPP (Jabber) server and use libraries such as Smack API a Java library for both Android and Java backend and JavaScript libraries such as Strophejs for connecting to your Jabber server. Personally I’ve never used Tigase or Prosody, but when it comes to performance I highly recommend using Ejabberd.