Kamailio Quick Install Guide for v5.2.x – Debian 9

This article will provide step-by-step instructions on how to install Kamailio 5.2.x on Debian using apt packages. This article assumes you have a fresh install of Debian 9.x.

Add Kamailio 5.2 repo and GPG key

vi /etc/apt/sources.list

Add the following lines to the file

deb http://deb.kamailio.org/kamailio52 stretch main
deb-src http://deb.kamailio.org/kamailio52 stretch main

Update the apt package manager so that it’s aware of the new repository.

apt update

You can look at the kamailio packages in the apt repository by typing:

apt search kam

Install Kamailio

apt install kamailio kamailio-mysql-module 

Set Kamailio to Start at Boot

systemctl enable kamailio

Install MariaDB

We will use MariaDB for the Kamailio database engine. Note, Kamailio has support for a number of database backends. But, we are going to use MariaDB

apt install mysql-server

Set MySQL to Start at Boot

systemctl enable mariadb

Start MySQL

systemctl start mariadb 

Configure Kamailio to use MariaDB

By default, Kamailio does not use MySQL. To change this we need to edit one of Kamailio’s configuration files.

vi /etc/kamailio/kamctlrc

Uncomment the DBENGINE parameter by removing the pound symbol and make sure the value equals MYSQL. The parameter should look like this afterwards:


Uncomment and setup the Database Read/Write and Database Read/Only fields. You can just use the default values for right now and you can change them at a later time.

## database read/write user

## password for database read/write user

## database read only user

## password for database read only user

Create the Kamailio Database Schema

The command will create all the users and tables needed by Kamailio. You will be prompted to put in the MySQL root password that you created in the install MySQL section of this document. You will be asked if you want to install different tables – just say “yes” to all the questions.

/usr/sbin/kamdbctl create

Below are all the prompts you will be presented:

MySQL password for root: ''
Install presence related tables? (y/n): y
Install tables for imc cpl siptrace domainpolicy carrierroute userblacklist htable purple uac pipelimit mtree sca mohqueue rtpproxy?
(y/n): y
Install tables for uid_auth_db uid_avp_db uid_domain uid_gflags uid_uri_db? (y/n): y

The following MySQL users and passwords are created (please change these in a production environment).
kamailio - (With default password 'kamailiorw') - user which has full access rights to 'kamailio' database.
kamailioro - (with default password 'kamailioro') - user which has read-only access rights to 'kamailio' database.

Enable MariaDB module and auth modules in the Kamailio Configuration

vi /etc/kamailio/kamailio.cfg

Add the following after #!KAMAILIO

#!define WITH_MYSQL
#!define WITH_AUTH

Update the DBURL line to match the username and password you set in /etc/kamailio/kamctlrc earlier

The line looks like this by default:

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

If you changed the username and password then the new user name and password would look like this

#!define DBURL "mysql://new_username:new_password@localhost/kamailio

The new_username and new_password fields would be replaced with the values you entered in the /etc/kamailio/kamctlrc file.

Start the Kamailio Server

service start kamailio

Note, the startup options for Kamailio is located at /etc/default/kamailio

Test Kamailio

In order to test that Kamailio is working correctly, I’m going to create a SIP user account and register that account using a softphone such as X-Lite, Linphone, or Zoiper

Create SIP User Accounts

The following command will create a new SIP User. Note, that the domain portion has to be specified unless you export the SIP_DOMAIN environment variable:

kamctl add extension@domain extension password

Here is what I created:

kamctl add 1001@dopensource.com opensourceisneat

Registering a SIP Softphone

Configure whichever softphone you choose with the following options:

User ID: 1001
Password: opensourceisneat

Once you are registered, you can view all the registered extensions in kamailio with the following command:

kamctl ul show

You will get something like this:

Domain:: location table=1024 records=1 max_slot=1 
AOR:: 1001 Contact:: sip:1001@;
rinstance=636c6f6dedce9a2b;transport=UDP Q= Expires:: 3559 
Callid:: OWNlYzg2YThmMmI1MGM1YjMyZTk3NjU2ZTdhMWFlN2E. 
Cseq:: 2 
User-agent:: Z 3.3.21937 r21903 
State:: CS_NEW Flags:: 0 Cflag:: 0 
Socket:: udp: Methods:: 5087 
Ruid:: uloc-5a2f0176-36a3-1 Reg-Id:: 0 
Last-Keepalive:: 1513030025 
Last-Modified:: 1513030025

Make a Test Call

You can call yourself by entering 1001 into your softphone. If it rings then you have a basic Kamailio server installed and ready to be configured to provide load balancing, failover, accounting, etc. As an exercise, you should create another SIP user account and register that user using another softphone and try calling between the two SIP users.

Enabling G.729 Codec in FreeSWITCH

This tutorial has been created to go over whats needed to configure the non-licensed version of the g729 codec.  This codec would normally cost a license fee, but recently the patent expired, which allows the codec to be used without paying a license fee.

Adding the needed repository:

The repository below is for Centos 7 64 bits:

rpm -ivh http://repo.okay.com.mx/centos/7/x86_64/release/okay-release-1-1.noarch.rpm

Installing g729 codec:

yum install freeswitch-codec-bcg729

Please edit the following config files:

In /etc/freeswitch/autoload_config/modules.conf.xml please replace mod_g729 with mod_bcg729
vim /etc/freeswitch/autoload_config/modules.conf.xml

The file should like the following when complete – Notice the third load module statement.  It now contains the license free mod_bcg729 module versus the mod_g729 module.

In /etc/freeswitch/vars.xml please replace mod_g729 with mod_bcg729.

vim /etc/freeswitch/vars.xml

Within the same config file edit the following line following line to ensure g729 is a preferred codec along with any other codec you have installed.

If the install has been done correctly you should be able to use g729 codec without an issue.