Install on Debian Stretch 9.4 the fabulous Asterisk 14 + Freepbx 14

….I know…. there are other alternatives compared to FreePbx that are equally effective, but…. I know well FreePbx and I do not want to learn new Asterisk-GUI !

For this reason in this post I’ll write about FreePbx.

The very first step is to install Debian 9.1: below some critical points.

Disk Partition
My choice: Guided – use entire – all file in one partition
In my situation the device is equipped with a small SSD HD, and it is useless to create strange partition-geometries: the machine is used only for the Asterisk-PBX.

Software Selection
My choice: only SSH server & standard system utilities

Fix IpAddress
Log in as root.

# nano /etc/network/interfaces

Now edit it so the bottom looks like this but with your network IP Address

.......
# The primary network interface
iface enp4s0 inet static
address <IpAddress>
netmask <Network Mask>
gateway <Gateway ip address>
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers <dns ip address>

Root SSH Access
You need to permit root user to get via SSH in order to facilitate the configuration steps.

# nano /etc/ssh/sshd_config

Add in Authentication section the next lines.

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

Before continuing…

# apt update
# apt upgrade

Att.: If using the upgrade process you receive a new kernel version you need to reboot !

Install dependencies
Here the difficulty is that FreePbx does not support yet PHP 7, which is the installed version by default in Debian 9 ! For this reason it is mandatory to remove PHP 7 and force to install PHP 5. To install this old version you have to add a new package source (sury.org) where the main repositories contain both PHP 5.6 and PHP 7.0 package.

# apt remove --purge php7*
# apt install curl apt-transport-https net-tools
# curl https://packages.sury.org/php/apt.gpg | apt-key add -
# nano /etc/apt/sources.list.d/suryorgapt.list

Add the next line & save.

deb https://packages.sury.org/php/ stretch main

After that you can update & install PHP vers. 5 & Apache & other stuff

# apt-get update
# apt-get install -y apache2 bison php5.6 php5.6-mbstring php5.6-curl php5.6-fpm php5.6-cli php5.6-mysql php-pear php5.6-gd php5.6-odbc curl sox libncurses5-dev libssl-dev default-libmysqlclient-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git unixodbc-dev uuid uuid-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libcurl4-openssl-dev libical-dev libneon27-dev libsrtp0-dev libspandsp-dev subversion libtool-bin python-dev php5.6-xml php5.6-gd default-mysql-client default-mysql-server default-mysql-client-core default-mysql-server-core bison flex mongodb dirmngr php5.6-cgi libapache2-mod-security2 libapache2-mod-php5.6

Now we need to install other dependency to compile Asterisk and other software,

# apt-get install -y build-essential linux-headers-`uname -r`

Last but not least you need to enable the rewrite mod for Apache.

# a2enmod rewrit 

Download Asterisk source files.

> cd /usr/src
# wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-14-current.tar.gz
# wget -O jansson.tar.gz https://github.com/akheron/jansson/archive/v2.10.tar.gz

Compile and Install jansson
Oss.: Jansson is a C library for manipulating JSON data and is used by asterisk.

# cd /usr/src
# tar vxfz jansson.tar.gz
# cd jansson-*
# autoreconf -i
# ./configure
# make -j4
# make install

Compile and Install Dahdi
Oss.: Dahdi stand for Digium Asterisk Hardware Device Interface, and is a collection of open source drivers, for linux, that are used to interface with a variety of telephony related hardware. Teorically it won’t not be necessary, unless you use digium hardware, but for the sake of completeness I prefer install it anyway.

# cd /usr/src
# cd /usr/src
# tar xvfz dahdi-linux-complete-current.tar.gz
# cd dahdi-linux-complete-2*
# make all
# make install
# make config

Compile and Install LibPri
Att.: LibPRI is a library that adds support for ISDN (PRI and BRI) and it is used by hardware telephony related to ISDN PRI and BRI. Also in this case it won’t not be necessary, unless you use related hardware, but for the sake of completeness I prefer install it anyway.

# cd /usr/src
# tar xvfz libpri-current.tar.gz
# cd libpri-1*
# make -j4
# make install

Compile and install Asterisk

# cd /usr/src
# tar xvfz asterisk-14-current.tar.gz
# cd asterisk-14.*
# ./contrib/scripts/install_prereq install
# ./configure --with-pjproject-bundled
# make menuselect

In menu select you can enable all the asterisk functionality, but usually all the options are already correctly selected. ‘Save & Exit’ to save and continue.
Att.: In my opinion it is useless to activate mp3 support. It doesn’t make sense in a telephony environment especially now that the hard disk have large dimensions and there is no problem of space. It is normally better to convert audio file offline.

Now it is possible compile and install asterisk.

# make -j4
# make install
# make config
# make samples
# ldconfig

Now I think that is preferable reboot completely the system and check the boot log to verify if there is any error. After that you can try to verify that asterisk is working correctly using the next command: using this you can login to asterisk console.

#asterisk -rvvv

Expected result

Asterisk 14.7.6, Copyright (C) 1999 - 2016, Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 14.7.6 currently running on pbxspare (pid = 2183)
pbxspare*CLI>

Install Asterisk Soundfiles

> cd /var/lib/asterisk/sounds
# wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-en-wav-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-wav-current.tar.gz
# tar xvf asterisk-core-sounds-en-wav-current.tar.gz
# tar xfz asterisk-extra-sounds-en-wav-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-en-g722-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-g722-current.tar.gz
# tar xfz asterisk-extra-sounds-en-g722-current.tar.gz
# tar xfz asterisk-core-sounds-en-g722-current.tar.gz

Install and Configure Apache

# service asterisk stop
# groupadd asterisk
# useradd -d /var/lib/asterisk -g asterisk asterisk
# chown -R asterisk:asterisk /var/spool/asterisk /var/run/asterisk /etc/asterisk /var/{lib,log,spool}/asterisk /usr/lib/asterisk /var/www
# sed -i 's/#AST_USER="asterisk"/AST_USER="asterisk"/g' /etc/default/asterisk
# sed -i 's/#AST_GROUP="asterisk"/AST_GROUP="asterisk"/g' /etc/default/asterisk
# cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_BK
# sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
# sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
# mv /var/www/html /var/www/html.bak

In /etc/php/5.6/apache2/php.ini change memory_limit to 256M.

memory_limit = 256M

Install and Configure ODBC
FreePbx use libmyodbc that is currently missing from Debian Stretch repo. For this reason you have to download the lib from Download Connector/ODBC (pls check linkografia).
Here you need to select “Select Operating System” equal to Linux generic and download “Linux – Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive”. Put this file in /tmp.

# cd /tmp
# tar -xvf mysql-connector-odbc-5.3.10-linux-glibc2.12-x86-64bit.tar.gz
# cp mysql-connector-odbc-5.3.10-linux-glibc2.12-x86-64bit/lib/libmyodbc5* /usr/lib/x86_64-linux-gnu/odbc/

Att.: Your version can be different.

# nano /etc/odbcinst.ini

Add the next lines.

[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc5S.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1
# nano /etc/odbc.ini

Add the next lines.

[MySQL-asteriskcdrdb]
Description=MySQL connection to 'asteriskcdrdb' database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/run/mysqld/mysqld.sock
option=3

Now I think that is preferable reboot completely the system and check the boot log to verify if there is any error.

# a2enmod rewrite
# a2enconf php5.6-fpm
# a2enmod proxy_fcgi setenvif
# service apache2 restart

Install and Configure FreePbx

# nano /etc/asterisk/asterisk.conf

Remove the (!) from the first line.
From this

[directories](!)
....

to

[directories]
....

After that it is possible to download and install FreePbx.


# cd /usr/src
# wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-14.0-latest.tgz
# tar vxfz freepbx-14.0-latest.tgz
# cd freepbx
# ./install -n

That's all

Likografia
Download Connector/ODBC
Asterisk 14 Freepbx 14 su Debian Stretch 9.1