--- title: "⚡ Part 3: Compiling and Packaging Kamailio on Debian 13 (Trixie)" description: "Documentation for 3. Package Kamailio" --- *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 Telephony Server 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: 1. **Access to the Latest Features**: Target the stable `6.1` upstream branch. 2. **Custom Modules**: Build only the modules we require (e.g., PostgreSQL support, JSON/JWT processing, WebSockets, or TLS). 3. **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 ```bash apt-get update apt-get install -y \ sudo git build-essential devscripts dpkg-dev equivs fakeroot \ autoconf automake libtool libtool-bin cmake pkg-config \ wget curl unzip python-is-python3 python3-all-dev \ python3-setuptools docbook-xsl xsltproc \ libglib2.0-dev graphviz dh-make ``` ### 1.2 Install Kamailio Build Prerequisites Install the developer libraries required to compile Kamailio's core modules: ```bash apt-get install -y \ debhelper dh-cmake dh-sequence-cmake bison flex cmake \ default-libmysqlclient-dev docbook-xml docbook-xsl \ erlang-dev libcurl4-openssl-dev libev-dev libevent-dev \ libexpat1-dev libhiredis-dev libjansson-dev libjson-c-dev \ libjwt-dev libldap2-dev liblua5.4-dev libmaxminddb-dev \ libmemcached-dev libmicrohttpd-dev libmnl-dev libmongoc-dev \ libmosquitto-dev libnats-dev libncurses-dev libnghttp2-dev \ libpcre2-dev libperl-dev libphonenumber-dev libpq-dev \ librabbitmq-dev libradcli-dev librdkafka-dev libreadline-dev \ libsasl2-dev libsctp-dev libsecp256k1-dev libsecsipid-dev \ libsnmp-dev libsqlite3-dev libssl-dev libsystemd-dev \ libunistring-dev libwebsockets-dev libwolfssl-dev libxml2-dev \ lynx openssl python3 python3-dev ruby-dev \ unixodbc-dev uuid-dev zlib1g-dev ``` --- ## ⚙️ 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: ```bash mkdir -p /usr/src/kamailio/deb git clone -b 6.1 https://github.com/kamailio/kamailio.git /usr/src/kamailio/src cd /usr/src/kamailio/src # Link native Debian Trixie packaging control files ln -s pkg/kamailio/deb/trixie debian # Rename source and binary packages in debian/control to start with sbc-kamailio # This adds Provides/Conflicts/Replaces to prevent collisions with official Debian packages python3 -c " import re, os content = open('debian/control').read() # Prefix all occurrences of kamailio with sbc- content = re.sub(r'(? [!TIP] > **Handling Version Mismatches & Warnings (`dch warning`)**: > If you specify a static version (e.g., `6.1.0-0+sbc`) and `dch` warns that *`new version is less than the current version number (6.1.4)`*, the source branch contains newer maintenance updates. Always use the extracted `${CURRENT_VER}` or match the exact upstream version (e.g., `6.1.4-0+sbc`) to prevent package downgrade conflicts in APT. > [!NOTE] > **Debian Packaging Link**: Linking `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: ```bash make cfg ``` ### 2.3 Build Debian Packages Clean the workspace and trigger compilation: ```bash # Clean packaging workspace fakeroot debian/rules clean # Compile binary-only packages without signing metadata dpkg-buildpackage -us -uc -b -j$(nproc) # Move all generated packages and build receipts to our deb directory mv /usr/src/kamailio/*.deb /usr/src/kamailio/deb/ mv /usr/src/kamailio/*.changes /usr/src/kamailio/deb/ 2>/dev/null || true mv /usr/src/kamailio/*.buildinfo /usr/src/kamailio/deb/ 2>/dev/null || true ``` 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. From your build node, secure copy the packages directly to the repository upload directory: ```bash scp /usr/src/kamailio/deb/*.deb root@:/usr/src/ scp /usr/src/kamailio/deb/*.deb root@76.13.102.153:/usr/src/ ``` ### 3.1 Upload Packages Log into your repository server over SSH, organize the files into their target component directories, and rebuild the repository signatures: ```bash ssh root@ # Sort packages into pool components (base, extras, devel, etc.) CopyPackagesToRepo # Rebuild package indexes and sign Release signatures BuildRepoRing2All ``` 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 Telephony Server 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: ```bash wget -qO- https://repo.softswitchone.com/apt/setup_repo | bash ``` ### 4.2 Install Packages Update the local package manager and install Kamailio alongside PostgreSQL and WebSocket modules: ```bash apt-get update # Install Kamailio and its essential modules apt-get install -y \ sbc-kamailio \ sbc-kamailio-postgres-modules \ sbc-kamailio-presence-modules \ sbc-kamailio-websocket-modules # Verify the installation and check the compiled version kamailio -v ``` *Example Output:* ```text kamailio 6.1.4 (x86_64/linux) ``` > [!NOTE] > **What to do if a different version is returned?**: > * **Newer Point/Patch Release (e.g., `6.1.4`, `6.1.5`)**: This is normal and expected when building from the stable maintenance branch `6.1`, as it continuously incorporates verified bugfixes and patches. > * **Unexpected / Older Release (e.g., `5.8.x` or default Debian upstream version)**: > 1. Check if the binary was installed from Debian's official repository instead of your custom repository: > ```bash > apt-cache policy sbc-kamailio > ``` > 2. If conflicting packages exist, remove the generic package (`apt-get purge kamailio*`) and install the custom packages (`apt-get install sbc-kamailio sbc-kamailio-postgres-modules ...`). > 3. Verify binary path resolution: > ```bash > which kamailio > /usr/sbin/kamailio -v > ``` --- ## 🏁 Series Summary & Best Practices Congratulations! You have completed the 3-part Packaging and Repository series. Here is a review of what we built: 1. **Part 1**: Deployed an HTTPS-enabled repository server with RSA GPG key signing and automated indexing scripts. 2. **Part 2**: Built Telephony Server and its core telephony dependencies (SpanDSP, Sofia-SIP, libks2, etc.) from source, and published them. 3. **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 Telephony Server modules, make sure to keep parallel compilation turned off (`parallel=1`) to prevent build locks.