Kamailio v5 with Siremis GUI v5 on Debian v9 MariaDB Apache Install Guide

Kamailio sip router
Kamailio® is an Open Source SIP Server released under GPL, able to handle thousands of call setups per second. Kamailio can be used to build large platforms for VoIP and realtime communications – presence, WebRTC, Instant messaging and other applications.  Moreover, it can be easily used for scaling up SIP-to-PSTN gateways, PBX systems or media servers like Asterisk™, FreeSWITCH™ etc.

Siremis is a web management interface for Kamailio.  It allows configuration of user profiles, routing rules, view accounting, registered phones, display charts etc.

This guide was tested using:

Debian v9 (Stretch) x64
Kamailio v5
Siremis v5

Pre-install

apt update && apt upgrade
apt install dbus nano sudo curl git lsb-release mariadb-server apache2

PHP

apt install php php-mysql php-gd php-curl php-xml php-xmlrpc php-pear

Set PHP timezone.

## FIND YOUR TIMEZONE
tzselect
nano +924 /etc/php/7.0/apache2/php.ini
#For example
date.timezone = America/Vancouver
systemctl restart apache2

XML_RPC

cd /usr/src
# wget http://pear.php.net/get/XML_RPC-1.5.5.tgz
# If above link is not working try this link
wget https://src.fedoraproject.org/repo/pkgs/php-pear/XML_RPC-1.5.5.tgz/\
02f9b1a27636527ddf6661e545799d45/XML_RPC-1.5.5.tgz
pear upgrade XML_RPC-1.5.5.tgz 

Disable Firewall

It is sometimes helpful to disable the firewall during installation.

systemctl disable firewalld
systemctl disable iptables
systemctl stop firewalld
systemctl stop iptables

System Timezone

## FIND YOUR TIMEZONE
tzselect

## SET TIMEZONE EXAMPLE
timedatectl set-timezone America/Vancouver

## CHECK TIMEZONE
​timedatectl status
systemctl restart rsyslog

Kamailio

wget -O- http://deb.kamailio.org/kamailiodebkey.gpg | sudo apt-key add -
echo "deb http://deb.kamailio.org/kamailio51 $(lsb_release -sc) main" >/etc/apt/sources.list.d/kamailio.list
apt update && apt install kamailio kamailio-mysql-modules kamailio-presence-modules kamailio-xml-modules

nano /etc/kamailio/kamctlrc and uncomment the DBENGINE and CHARSET lines as follows

DBENGINE=MYSQL
CHARSET="latin1"

Create Kamailio database

kamdbctl create

Answer y to everything.

Configure Kamailio

cd /etc/kamailio/
cp kamailio.cfg kamailio.cfg.orig

Replace kamilio.cfg with this pre-configured kamailio.cfg file.  Alternatively, edit kamailio.cfg manually as follows.

The top of the file should look like the following:

#!KAMAILIO
#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
#!define WITH_PRESENCE
##!define WITH_NAT
##!define WITH_TLS
#!define WITH_ACCDB
#!define WITH_XMLRPC
#!define WITH_JSONRPC
##!define WITH_DEBUG
Add this part around line #250 in with the other loadmodule statements
# -- for siremis CDRs --------------
loadmodule "rtimer.so"
loadmodule "sqlops.so"

Add this part around line 290

# -- For XMLRPC --------------------
#!ifdef WITH_XMLRPC
loadmodule "xmlrpc.so"
#!endif

# -- For JSONRPC -------------------
#!ifdef WITH_JSONRPC
loadmodule "jsonrpcs.so"
#!endif

Add the following around line 450

#!ifdef WITH_XMLRPC
# ----- xmlrpc params -----
modparam("xmlrpc", "route", "XMLRPC")
modparam("xmlrpc", "url_match", "^/RPC")
#!endif

#!ifdef WITH_JSONRPC
# ----- jsonrpcs params -----
modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")
modparam("jsonrpcs", "dgram_mode", 0666)
#!endif
Add the following around line #470 at the end of the modparam section before the routing logic section.
# -- for siremis CDRs --------------
modparam("rtimer", "timer", "name=cdr;interval=300;mode=1;")
modparam("rtimer", "exec", "timer=cdr;route=CDRS")
modparam("sqlops", "sqlcon", "cb=>mysql://kamailio:kamailiorw@localhost/kamailio")
Finally, add this at the end of the routing section around line #910
# ======================================================
# Populate CDRs Table of Siremis
# ======================================================
route[CDRS] {
    sql_query("cb","call kamailio_cdrs()","rb");
    sql_query("cb","call kamailio_rating('default')","rb");
    }


# XMLRPC routing
#!ifdef WITH_XMLRPC
route[XMLRPC] {
    # allow XMLRPC from localhost
    if ((method=="POST" || method=="GET")
            && (src_ip==127.0.0.1)) {
        # close connection only for xmlrpclib user agents (there is a bug in
        # xmlrpclib: it waits for EOF before interpreting the response).
        if ($hdr(User-Agent) =~ "xmlrpclib")
            set_reply_close();
        set_reply_no_connect();
        dispatch_rpc();
        exit;
    }
    send_reply("403", "Forbidden");
    exit;
}
#!endif
Pointing SIP clients to a FQDN instead of an IP address requires a local alias.  The commented out example is located around line #170 in /etc/kamailio/kamailio.cfg.   You can specify multiple aliases by repeating that line
/* add local domain aliases */
alias="your_server_fqdn"
alias="your_server_fqdn2"
systemctl restart kamailio

Siremis

cd /var/www
git clone https://github.com/asipto/siremis

Create apache config file.  

cat >> /etc/apache2/sites-available/siremis.conf << EOF
<VirtualHost *:80>

    #ServerName www.example.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog /var/log/apache2/error.log
    CustomLog /var/log/apache2/access.log combined

    Alias /siremis "/var/www/siremis/siremis"
    <Directory "/var/www/siremis/siremis">
    
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted

            <FilesMatch "\.xml$">
                Require all denied
            </FilesMatch>

            <FilesMatch "\.inc$">
                Require all denied
            </FilesMatch>

      </Directory>

</VirtualHost>
EOF
a2dissite 000-default
a2ensite siremis
a2enmod rewrite
systemctl restart apache2

Create Siremis configs and set permissions

cd /var/www/siremis
make prepare24
make chown

Create MySQL user

mysql -e "GRANT ALL PRIVILEGES ON siremis.* TO siremis@localhost IDENTIFIED BY 'siremisrw';"

Lock down the database

mysql_secure_installation

Answer Y to everything.

 

Run the web install wizard from a web browser at http://your_server_ip_or_fqdn/siremis

Siremis web wizard page 1

Siremis web wizard page 2

Siremis web wizard page 4

*Note: The above image shows that all 4 boxes should be checked for a first time install.

Siremis web wizard page 4

Siremis web wizard page 5

If you want to run the install wizard again
chmod 755 /var/www/siremis/siremis/install
rm -rf /var/www/siremis/siremis/install.lock

Otherwise

chmod 000 /var/www/siremis/siremis/install

Administration

Change admin password and email

Kamailio administration change username and password1

Siremis administration change password and username 2

Add SIP users

Siremis administration add SIP users 1

Siremis Administration add SIP users 2

Misc

Firewall

apt -y install firewalld
systemctl enable firewalld
systemctl start firewalld

firewall-cmd --permanent --zone=public --add-service={http,https}
firewall-cmd --permanent --zone=public --add-port={5060,5061}/tcp
firewall-cmd --permanent --zone=public --add-port={5060,5061}/udp
firewall-cmd --reload
firewall-cmd --list-all

Log file

To write Kamailio logs to a separate log file in addition to /var/log/syslog.

## Add the following line to /etc/rsyslog.conf
local0.*             -/var/log/kamailio.log
touch /var/log/kamailio.log
systemctl restart rsyslog

References:
Siremis v5.1.x - Installation

Sections: