Install Kamailio On Debian

For more details about Kamailio Project visit: kamailio.org.

Overview

Kamailio packages are included in the official Debian Stable repository since version 8.0, and continues to be in the current Stable (9.x, codename Stretch).

This tutorial should just work for latest Ubuntu versions as well.

The focus of this tutorial is to install Kamailio with MySQL backend using deb packages.

Alternative APT Repositories

Debian Stable includes the Kamailio version which was available at the time of their release. Giving that Debian is releasing a new major version like every 2 years, the Kamailio included in the distro can be older than the current stable release.

If you want to use a more recent version of Kamailio, you can use the APT repositories hosted by Kamailio project.

The list of APT repositories offered by Kamailio project for various Debian or Ubuntu versions, including nightly builds for stable and development versions, is presented at:

For example, if you want to install Kamailio v5.5.x on Debian Buster (10.x), add the next URLs to APT configuration:

deb     http://deb.kamailio.org/kamailio55 buster main
deb-src http://deb.kamailio.org/kamailio55 buster main

APT Repositories Archive

The APT repositories linked in the previous session contain only the packages for the latest versions of Kamailio from stable branches. If you want to install an older version or rollback to an older version, use the repositories listed at:

For example, to install Kamailio v5.5.1, add the next URL to APT configuration:

deb https://deb-archive.kamailio.org/repos/kamailio-5.5.1

APT Install Commands

The apt tool is used for installing the packages. First run the update command to sync with the remote repository, then install MySQL server, Kamailio core and mysql packages.

apt update
apt install default-mysql-server
apt install kamailio kamailio-mysql-modules

Once the above commands are finished, you can check if kamailio application is available:

which kamailio

There are many Kamailio packages specific for various modules. You can see all available with:

apt search kamailio

For example, to be able to load websocket module, you have to install the package kamailio-websocket-modules:

apt install kamailio-websocket-modules

Configuration Files

Configuration files are located in /etc/kamailio/ folder.

kamctlrc

The /etc/kamailio/kamctlrc is the configuration file for kamctl and kamdbctl tools. You need to edit it and set the SIP_DOMAIN to your SIP service domain (or IP address if you don't have a DNS hostname associated with your SIP service).

Set also the DBENGINE to be MYSQL and adjust other setting as you want. Very important are the passwords to connect to MySQL server, respectively DBRWPW and DBROPW. By default, their values are kamailiorw and kamailioro. You should change them before executing kamdbctl create (step detailed the section Create Database).

kamailio.cfg

The /etc/kamailio/kamailio.cfg is the configuration file for kamailio. Edit it to enable some of the features shipped with it.

To enable use of MySQL server backend, user authentication and persistent user location, add after the first line:

#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB

Create Database

To create the database structure needed by Kamailio, run:

kamdbctl create

The database name created in MySQL is kamailio. Two access users to MySQL server were created:

  • kamailio - (with password set by DBRWPW in kamctlrc) - user which has full access rights to kamailio database

  • kamailioro - ((with password set by DBROPW in kamctlrc) - user which has read-only access rights to kamailio database

The access for the two users is restricted to localhost, but as advised above, it is recommended to change their default passwords.

If you changed the value of DBRWPW in kamctlrc, you must update the value of DBURL define inside kamailio.cfg.

#!define DBURL "mysql://kamailio:_NEW_DBRWPW_@localhost/kamailio"

Startup Scripts

Init.d Scripts

Depending on startup system, you may have an /etc/init.d/kamailio script that you can use to start/stop kamailio.

First you should edit /etc/default/kamailio and adjust the setting for kamailio startup script, in particular the one that enables kamailio to start.

/etc/init.d/kamailio start
/etc/init.d/kamailio stop

Systemd Scripts

If the default startup system is systemd, then kamailio can be managed via systemctl:

systemctl start kamailio
systemctl stop kamailio

First you may also need to edit /etc/default/kamailio and adjust the setting for kamailio startup script, in particular the one that enables kamailio to start.

Adding Subscribers

To add subscribers (users), you can use the kamctl command:

kamctl add userid password

Like:

kamctl add alice secret

Then you can configure your phone to register to Kamailio using the username and password set in the above command.

Support

Questions about how to use Kamailio and the content of kamailio.cfg can be addressed via email to:

More documentation resources can be found at:

Contributions

Anyone is welcome to contribute to this document. It is recommended to make a pull request via:

This version of the document is in GIT branch master.

Errors and other issues can be reported via the tracker at: