Basic Ejabberd install/setup on ubuntu (External Script Authentication)

In first article, I discussed the installation and normal chat with users registered internally. Now i am going to discuss the external authentication through a php script.

If you want to authenticate users via your database. their are two alternatives.
1. Using odbc, It have one restriction as its internal database have and that is password must be stored plain. (Latest version may not have this restriction.)
2. Using external authentication script. In this way you can authenticate user via a custom script. Here one good php script can be found there. Now download an extract in some location of your system (not necesarily on apache document root as it will working as cli script ).

Now first create a php script in same folder. I name it auth.php. This file should have similar code suggested at github page. I am updating it using some real query.

require 'ejabberd_external_auth.php';
class Auth extends EjabberdExternalAuth {
    protected function authenticate($user, $server, $password) {
        $stmt = $this->db()->prepare("SELECT user_id FROM user WHERE username = ? AND password = ? ");
        $stmt->execute(array($user, password));
        if($stmt->rowCount() >= 0 )
            return true;
            return false;

    protected function exists($user, $server) {
        $stmt = $this->db()->prepare("SELECT user_id FROM user WHERE username = ? ");
        if($stmt->rowCount() >= 0 )
            return true;
            return false;
$pdo = new PDO('mysql:dbname=testdb;host=', 'user', 'password');
new Auth($pdo, 'auth.log');

I skipped $server argument in query check as If you need only users for one chat server. If you need to handle multiple servers then you may need to change code to reflect server too in query.

Now comment internal auth_method by

%%{auth_method, internal}.

And uncomment, change the line

{auth_method, external}.
{extauth_program, "/path/to/auth.php"}.

gave executing permission to auth.php by chmod 0755 auth.php.

NOTE – As this script executed by ejabberd user created at time of ejabberd installation. So this script need execute permission for ejabberd. You may add ejabberd to your user’s group and gave group to execute permission or gave other to execute permission. In both case it is advisable to check execute file after login through other user.

Add chat users in your user table. You will also need admin user to add into your DB with same password to run admin console.

Now restart ejabberd. and verify by adding user at you jabber client. if it going failed. Then verify log file var/log/ejabberd.log. If file have error to not connecting. check php script again for any error.

Ejabberd default enabled MUC (multi user chat or several other modules ), So you can verify/use also this functionality too.

That’s all for this article, In next article I will discuss message logging.

Basic Ejabberd install/setup on ubuntu

In social web appliactions, Jabber chat comes as popular choice for implementing self chat gateway/servers. While there are several chat server are available in market like ejabberd, jabberd2, openfire.
Ejabberd is chat server built in erlang. It provide various recommended features by core/plugins.

Now I am going to give some information for setup ejabberd chat server onto Ubuntu 12.04.

First you need to install ejabberd package. There are two ways.
1. Through ubunty repository. While this option require less work, But you may not get latest package for ejabberd.
2. Download ejabberd package and compile it. This option require more work, But you can get latest package havig more features.

We going through First easy approach.
Here we install ejabberd via

sudo apt-get install ejabberd ejabberd-tools

After installation completion, we will doing some intial setup and configuration.
We need to configure our first chat domain. Here we have config file names ejabberd.cfg at /etc/ejabberd folder.
Open it into your editor, and go for line look like below.

{hosts, ["localhost"]}.

Then change it to add your domain/ip-address as Chat server host.

{hosts, ["localhost",""]}.

Also setup your admin user via change config.

{acl, admin, {user, "", "localhost"}}.


{acl, admin, {user, "administrator", "localhost"}}.

Where administrator is admin-name chosen by you. (Ofcourse you can choose any name as admin.)

After save you should also register your admin via command run on shell.

ejabberdctl register administrator localhost password

Now you should restart ejabberd by executing commands

sudo /etc/init.d/ejabberd restart

Open Admin Console via the url – http;//localhost:5280/admin. It ask you the enter admin credentials. enter administrator name and its password, setup via ejabberctl.
Here you can add users via going to virtual hosts -> localhost[] ->  Users.

After register users at here you can start chat by your jabber client example pidgin or spark.

Ejabberd default using it internal database called mnesia to store all kind of information like users, room, logs etc.

In second article of series, I will discuss the external authentication and logging.