Setting up an XMPP server for use with drupal

Events happening in the community are now at Drupal community events on www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

Some terms and explanations used in this guide:

  • Term = Definition
  • JID = Jabber ID (The user id originally created for the Jabber IM client)
  • roster = A list of "Friends" connected to your JID
  • stanza = A fixed number of lines of verse forming a unit of a poem. In XMPP a fixed number of data send in packets?
  • disco = Discovery of the services delivered by this XMPP server.
  • MUC = Multi User Chat, or group chat.
  • PubSub = (Publish/Subscribe) In the Pub/Sub model, subscribers typically receive only a subset of the total messages published. Publish/Subscribe
  • BOSH = Bidirectional-streams Over Synchronous HTTP (BOSH) is a transport protocol that emulates a bidirectional stream between two entities (such as a client and a server) by using multiple synchronous HTTP request/response pairs without requiring the use of polling or asynchronous chunking. Draft Standard
  • Strophe.js = Strophe is a family of libraries for writing XMPP clients. libstrophe is a C library with minimal dependencies. Strophe.js is a pure-JavaScript library. The implementations are production ready, well documented, easy to use, and easy to extend.

XMPP Servers

The most popular open source XMPP servers are probably ejabberd and OpenFire.
Wikipedia had a list but Wikipedia's list of XMPP server was deleted on the 4th of July, 2010. You can read more about why here.
Edit: You can use this page for more details
http://en.wikipedia.org/wiki/Comparison_of_XMPP_server_software

Install and configure ejabberd on Debian / Ubuntu / apt-get based systems

The easiest way to install ejabberd on Ubuntu is via the package manager apt-get. If you are still on Hardy (8.04), make sure to unrecommended the hardy backports in /etc/apt/sources.list, else you get the version 1.1.4 version of ejabberd.

If you are using Ubuntu 11.10, you probably don't need to edit your sources list.

It is also possible to compile ejabberd yourself from source. Here is a Screencast for setting up ejabberd from source. (SOMEONE TRIED THIS WITH SUCCESS?)

First make sure your system is up to date:

$> sudo aptitude update
$> sudo aptitude full-upgrade    // safe-upgrade is for mietjes

(mietjes)

Now install ejabberd:

$> sudo aptitude install ejabberd

You will see there are a lot of depending packages installed too.

To define the host-name and administrator user in ejabberd it is easiest to let Debian do it for you:

$> sudo dpkg-reconfigure ejabberd

It will ask you for the host-name, an administrator user name and for the password (twice). Best to choose a username not used on the drupal site, else that user on the drupal site can't be registered on the XMPP server. Configure DNS for the hostname you use here, if you sigin as yname@xmpp.yserver.com, the XMPP client will connect to xmpp.yserver.com:5222.
For discussion: what is the best host-name? What i mean is when you have the site http://drupal.org, is the hostname the "drupal.org" or xmpp.drupal.org. I am inclined to go with the first one. The user on drupal.org gets the name <d.o username>@drupal.org, instead of <d.o username>@xmpp.drupal.org.

Restart ejabberd:

$> sudo /etc/init.d/ejabberd restart

If you have a firewall, make sure you open those ports:

  • 5222 for XMPP client connections (c2s = client to server)
  • 5269 for XMPP server connections (s2s = server to server). If you want that users in your server NOT be able to chat with users of other servers, you can close the port 5269.
  • 5280 for HTTP client connections, including HTTP-Bind and WebAdmin. Needed for http_bind in Strophe.js

Now you should be able to login to your ejabberd server from a XMPP client, for example using Pidgin:

  1. Go to the Pidgin menu Accounts -> Manage Accounts -> Add
  2. Select XMPP as protocol, user name is the user you configured in dpkg-reconfigure, domain is the host-name, resource pidgin (is not really important) and the password you configured earlier.
  3. Click Add and there you are!
  4. Because you are the administrator of this server, you should see a lot of possible functions under Accounts -> username@servername.

A web-interface to ejabberd is available. Point your browser to http://yourserver.com:5280/admin and login with the credentials you configured earlier. Not much to see now, but later it can become handy for debugging your setup with the drupal module.

If you use the Drupal module DXMPP or another BOSH based library, you have to enable http-bind in the ejabberd configuration file. As http-poll protocol isn't needed, you can disable it.

$> sudo vim /etc/ejabberd/ejabberd.cfg

Here is a diff file of the Ubuntu Karmic (9.10) original file:
diff --git a/ejabberd/ejabberd.cfg b/ejabberd/ejabberd.cfg
index b5ab8a0..129abda 100644
--- a/ejabberd/ejabberd.cfg
+++ b/ejabberd/ejabberd.cfg
@@ -185,11 +185,10 @@
   %%              ]},

   {5280, ejabberd_http, [
-           http_poll,
+            http_bind,
             web_admin
                         ]}
   ]}.

@@ -425,7 +424,7 @@
% (note that if you remove mod_register from modules list then users will not
% be able to change their password as well as register).
% This setting is default because it's more safe.
-{access, register, [{deny, all}]}.
+{access, register, [{allow, all}]}.

%% Everybody can create pubsub nodes
{access, pubsub_createnode, [{allow, all}]}.
@@ -446,8 +445,10 @@
%%
%% Modules enabled in all ejabberd virtual hosts.
%%
+{registration_timeout, infinity}.
{modules,
  [
+  {mod_http_bind,[]},
   {mod_adhoc,    []},
   {mod_announce, [{access, announce}]}, % requires mod_adhoc
   {mod_caps,     []},

What is changed:
  • Removed http-poll on port 5280
  • Added http-bind on port 5280
  • Enabled registering of new users, needed for the Drupal DXMPP module. @TODO Is it possible to limit registration only from our site? Now anybody can register on our server!! @ANSWER Yes, I think you can just block access on port 5222 from all but the Drupal server. Of course, then your users are limited to using the provided web interface for chat.
  • changed registration_timeout to unlimited. Default is 600 seconds. The server should wait 5 minutes before they can register a second new user. Together with open registering this is really a security problem, a hacker can register millions of new user in a short time!
  • Added the http_bind module. Is not standard in the Ubuntu package
  • @TODO: which modules can be removed? I think at least mod_irc & mod_pubsub can be removed.

ejabberd-modules

There may be some additional ejabberd modules you'll need to download and install. Before you can do that, however, you'll need to have the erlang-dev package installed:

sudo aptitude install erlang-dev

Then get the ejabberd-modules package itself:

svn co https://svn.process-one.net/ejabberd-modules

Then follow the instructions for the individual module you'll need. Generally that is:

  1. going to the module folder
  2. running ./build.sh
  3. copying the resultant \*.beam files from its ebin folder to /usr/lib/ejabberd/ebin (maybe with sudo cp ebin/\* /usr/lib/ejabberd/ebin)
  4. enable the new module in the ejabberd config file (sudo vim /etc/ejabberd/ejabberd.cfg)
  5. and restarting ejabberd.

See http://www.ejabberd.im/ejabberd-modules for more detailed instructions.

Making BOSH work

The DXMPP Drupal module uses Strophe.js to communicate with the XMPP server. Strophe.js is using BOSH, which means we are going to communicate with the ejabberd server on the URL http://yourserver.com/http-bind/, but now this service is only available via http://yourserver.com:5280/http-bind/. To solve this problem we are going to use the Apache (of Nginx) server as a proxy. Best place to do this is in the file /etc/apache/mods-available/proxy.conf. Of course you can do it in the section of the drupal site or in the main /etc/apache2/httpd.conf configuration file.

First we enable the proxy-http:

$> sudo a2enmod proxy_http
$>

Then we add some lines to /etc/apache/mods-available/proxy.conf, just between the lines: "ProxyVia On" and "". Replace yourserver.com with your servername.

     ..... existing code.... not changing ....
        ProxyVia On

        <Proxy http://yourserver.com:5280/http-bind>
               Order allow,deny
               Allow from all
        </Proxy>

ProxyPass /http-bind http://yourserver.com:5280/http-bind
ProxyPassReverse /http-bind http://yourserver.com:5280/http-bind

</IfModule>

Restart Apache:

$> sudo /etc/init.d/apache2 restart

If everything went alright, you can point your browser to http://yourserver.com/http-bind/ and get something like:

Ejabberd mod_http_bind v1.2

An implementation of XMPP over BOSH (XEP-0206)

Success!!

You are ready, install XMPP modules on your Drupal site and enjoy:-)

Install and configure ejabberd on CentOs / yum based systems

Install and configure OpenFire on Debian / Ubuntu / apt-get based systems

1) Log into the Ubuntu server dedicated for Openfire.
2) Update the server.

apt-get update
apt-get dist-upgrade

3) Install the necessary programs for Openfire.
apt-get install apache2 php5 libapache2-mod-php5 mysql-server-5.0 sun-java6-bin

4) Before we download Openfire we need to first add the Openfire database and user.
mysql -u root -p
create database openfire;
grant all on openfire.* to openfire@localhost IDENTIFIED BY "password";
exit

5) Change directories to /opt .
6) Download Openfire.
wget http://www.igniterealtime.org/downloadServlet?filename=openfire/openfire_3_6_4.tar.gz

7) Untar the file
tar -xzvf openfire_3_6_4.tar.gz

8) Change to Openfire bin
cd openfire/bin

9) Start Openfire
./openfire start

10) Openfire may take a minute to start up, but once ready should be accessible via the web interface.
http://server_ip:9090

11) You will now be directed through a bunch of screens to help initially configure Openfire.

Install and configure OpenFire on CentOs / yum based systems

Configuring XMPP chat into your Drupal site

See the follow guide:

http://dueyesterday.net/node/36

XMPP

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: