⚡ Part 3: Compiling and Packaging Kamailio on Debian 13 (Trixie)
Welcome to the third and final installment of our "Debian 13 Packaging & Distribution" series. In the previous parts, we set up our GPG-signed APT repository and compiled the FreeSWITCH telephony core. Now, we will compile and package Kamailio (v6.1), the high-performance SIP routing engine, from source on Debian 13. Finally, we will publish the resulting modular packages to our custom repository server and perform an end-to-end client installation.🏗️ Why Compile Kamailio from Source?
While Debian provides pre-compiled Kamailio packages in its upstream repositories, they are often lagging behind the latest stable upstream branch or missing custom modules. Compiling Kamailio on our own build node gives us:
- Access to the Latest Features: Target the stable
6.1upstream branch. - Custom Modules: Build only the modules we require (e.g., PostgreSQL support, JSON/JWT processing, WebSockets, or TLS).
- Optimization: Compile binaries compiled specifically for your deployment target's processor architecture (e.g., AMD64 vs. ARM64).
🛠️ Phase 1: Environment & Dependency Setup
Kamailio has a modular architecture. In order to build database, presence, secure transport, and logging modules, we must install their corresponding development packages.
1.1 Install Compiling and Packaging Tools
1.2 Install Kamailio Build Prerequisites
Install the developer libraries required to compile Kamailio's core modules:
⚙️ Phase 2: Compiling & Packaging Kamailio
We clone Kamailio into /usr/src/kamailio/src. This isolates our build directories and outputs the packaged files in the parent directory (/usr/src/kamailio/), keeping our source tree clean.
2.1 Clone and Setup Packaging Links
Clone the stable 6.1 branch of Kamailio:
pkg/kamailio/deb/trixie to the debian directory is a crucial step. Kamailio maintains native, distribution-specific build scripts within its repository. This link instructs dpkg-buildpackage to use the official rules designed specifically for Debian 13.2.2 Generate Configuration
Create the build config targets:
2.3 Build Debian Packages
Clean the workspace and trigger compilation:
The directory /usr/src/kamailio/deb/ will now contain modular packages, including:
sbc-kamailio_.deb: The core binary and routing engine.
sbc-kamailio-postgres-modules_.deb: Database backends (PostgreSQL engine).
sbc-kamailio-presence-modules_.deb: Presence services (SIP SUBSCRIBE/NOTIFY, dialog info).
sbc-kamailio-websocket-modules_.deb: WebSocket engines (SIP-over-WebSockets for WebRTC clients).
🌐 Phase 3: Publishing Kamailio to the Custom Repository
With our packages compiled and located inside /usr/src/kamailio/deb/, we can push them to our repository server (IP: ) for distribution.
3.1 Upload Packages
From your build node, upload the Kamailio packages to the repository's incoming base pool:
3.2 Update Repository Metadata
Log into your repository server over SSH and rebuild the repository index:
The script cleans up older package builds, scans the new packages, updates Packages.gz indexes, and signs the Release logs cryptographically.
🚀 Phase 4: End-to-End Client Installation
To deploy both Kamailio and FreeSWITCH on a clean Debian 13 (Trixie) server, run these commands:
4.1 Setup the Repository
Run the repository bootstrap script to register the GPG key and APT source configurations:
4.2 Install Packages
Update the local package manager and install Kamailio alongside PostgreSQL and WebSocket modules:
Example Output:🏁 Series Summary & Best Practices
Congratulations! You have completed the 3-part Packaging and Repository series. Here is a review of what we built:
- Part 1: Deployed an HTTPS-enabled repository server with RSA GPG key signing and automated indexing scripts.
- Part 2: Built FreeSWITCH and its core telephony dependencies (SpanDSP, Sofia-SIP, libks2, etc.) from source, and published them.
- Part 3: Compiled Kamailio v6.1 from source using native packaging links and published its modular parts.
Best Practices for Maintenance
Version Pinning: On production nodes, configure APT pinning to prevent upstream Debian repositories from overwriting your custom-built packages. Clean Keyring Management: Always distribute the public signing GPG key via/etc/apt/keyrings/ instead of legacy deprecated paths like apt-key add.
- Sequential Builds: When rebuilding FreeSWITCH modules, make sure to keep parallel compilation turned off (
parallel=1) to prevent build locks.