Asterisk Freepbx on Debian (Debian v11, Asterisk v16 or v18, Freepbx v16)

Debian

 

 

This guide covers the installation of Asterisk v16 or v18 and Freepbx v16, from source, on Debian v9, v10, or v11.

Tested on

Debian v9 (Stretch), v10 (Buster), v11 (Bullseye), x64 minimal install
Asterisk v16 or v18
Freepbx v16
PHP v7.4

Assumptions

Console text mode (multi-user.target)
Installation done as root user (su - )

Prerequisites

Initial upgrade and install

apt update && apt -y upgrade && apt install lsb-release

PHP

# Install dependencies
apt -y install curl apt-transport-https ca-certificates
# Add php repository on Debian v9.  Optional for Debian v10 & v11 as v7.4 is included.
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > \
/etc/apt/sources.list.d/php.list
# Install PHP v7.4
apt update && apt -y install php7.4 php7.4-curl php7.4-cli php7.4-mysql php7.4-mbstring php7.4-gd php7.4-xml

Debian 9/10

# Debian 9/10 required packages.  Do not use for Debian ll.
apt -y install locales sngrep build-essential aptitude openssh-server apache2 mariadb-server mariadb-client bison doxygen flex php-pear curl sox libncurses5-dev libssl-dev libmariadbclient-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool-bin autoconf git subversion uuid uuid-dev libiksemel-dev tftpd postfix mailutils nano ntp libspandsp-dev libcurl4-openssl-dev libical-dev libneon27-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libsrtp*-dev unixodbc unixodbc-dev python-dev xinetd e2fsprogs dbus sudo xmlstarlet lame ffmpeg dirmngr linux-headers* gnupg2

Debian 11

# Debian 11 required packages.  Do not use for Debian 9/10
apt -y install locales sngrep build-essential aptitude openssh-server apache2 mariadb-server mariadb-client bison doxygen flex php-pear curl sox libncurses5-dev libssl-dev libmariadb-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool-bin autoconf git subversion uuid uuid-dev libiksemel-dev tftpd postfix mailutils nano ntp libspandsp-dev libcurl4-openssl-dev libical-dev libneon27-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libsrtp*-dev unixodbc unixodbc-dev python-dev xinetd e2fsprogs dbus sudo xmlstarlet lame ffmpeg dirmngr linux-headers* gnupg2

Node.js

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
apt -y install nodejs

ODBC

Install connector. 

It is possible newer versions may work. We have seen problems with newer versions in the past so we are sticking with this version in this procedure.

cd /usr/src
wget https://downloads.mariadb.com/Connectors/odbc/connector-odbc-2.0.19/\
mariadb-connector-odbc-2.0.19-ga-debian-x86_64.tar.gz
tar -zxvf mariadb-connector-odbc-2.0.19*.tar.gz
cp lib/libmaodbc.so /usr/lib/x86_64-linux-gnu/odbc/

Create /etc/odbcinst.ini

cat >> /etc/odbcinst.ini << EOF
[MySQL]
Description = ODBC for MariaDB
Driver = libmaodbc.so
FileUsage = 1
EOF

Create /etc/odbc.ini

cat >> /etc/odbc.ini << EOF
[MySQL-asteriskcdrdb]
Description = MariaDB connection to 'asteriskcdrdb' database
driver = MySQL
server = localhost
database = asteriskcdrdb
Port = 3306
Socket = /var/run/mysqld/mysqld.sock
option = 3
  
EOF

MongoDB

Only required if you plan to use XMPP.

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" \
| sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

apt update && apt install -y mongodb-org

systemctl enable mongod

Set Timezone

## FIND YOUR TIMEZONE
tzselect
## SET TIMEZONE EXAMPLE
timedatectl set-timezone America/Vancouver
timedatectl status
systemctl restart rsyslog

Install

DAHDI

Only required if using a physical server and installing telecom hardware.  At this time, versions newer than 2.10.2 (2.11.0 and 2.11.1) do not install correctly.

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-2.10.2+2.10.2.tar.gz
tar zxvf dahdi-linux-complete-2.10*
cd /usr/src/dahdi-linux-complete-2.10*/
make all && make install && make config
systemctl restart dahdi

If make all fails try reboot and run apt install linux-headers*

Asterisk

If upgrading an existing install with older Asterisk, it is best to run  rm -rf /usr/lib/asterisk/modules first.  If installing Asterisk v18, just replace asterisk-16 with asterisk-18 in the command lines

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz
tar zxvf asterisk-16-current.tar.gz
cd /usr/src/asterisk-16*/
make distclean

Install additional dependencies

cd /usr/src/asterisk-16*/
./contrib/scripts/install_prereq install

Configure

cd /usr/src/asterisk-16*/
./configure --with-jansson-bundled

To verify type nano -v config.log.

Set compile options

cd /usr/src/asterisk-16*/
make menuselect

# Go to Applications submenu and make sure app_macro is checked.
# To change compile options after install simply run make menuselect and make && make install again.

Create Asterisk User, compile, install and set preliminary ownership.

adduser asterisk --disabled-password --gecos "Asterisk User"
make && make install && chown -R asterisk. /var/lib/asterisk

Freepbx

cd /usr/src
git clone -b release/16.0 --single-branch https://github.com/freepbx/framework.git freepbx
touch /etc/asterisk/modules.conf
cd /usr/src/freepbx
./start_asterisk start

./install -n
# Minimal module install
fwconsole ma downloadinstall framework core voicemail sipsettings infoservices \
featurecodeadmin logfiles callrecording cdr dashboard music soundlang recordings conferences pm2
fwconsole chown
fwconsole reload

Optionally, install all modules (not recommended).  You may need to run the following commands twice.

fwconsole ma installall
fwconsole chown
fwconsole reload

Set Freepbx to start on boot

cat >> /etc/systemd/system/freepbx.service << EOF
[Unit]
Description=Freepbx
After=mariadb.service
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start -q
ExecStop=/usr/sbin/fwconsole stop -q
 
[Install]
WantedBy=multi-user.target

EOF
systemctl enable freepbx

Configure Apache

Add AllowOverride All to web directory so that .htaccess is active.

cat >> /etc/apache2/conf-available/allowoverride.conf << EOF 
<Directory /var/www/html>
    AllowOverride All
    </Directory>
EOF
a2enconf allowoverride

Change default apache user/group, disable index.html, enable rewrite module

sed -i 's/\(APACHE_RUN_USER=\)\(.*\)/\1asterisk/g' /etc/apache2/envvars
sed -i 's/\(APACHE_RUN_GROUP=\)\(.*\)/\1asterisk/g' /etc/apache2/envvars
chown asterisk. /run/lock/apache2
mv /var/www/html/index.html /var/www/html/index.html.disable
a2enmod rewrite
systemctl restart apache2

Reboot and access GUI

reboot

You should now be able to access the Freepbx GUI at http://yourserverIP

Post-install tasks are mandatory.

Post-install tasks

Lock down the database server.

mysql_secure_installation

Answer Y to everything.

Log File Rotation

If this is not done the log files will keep growing indefinitely.

nano /etc/logrotate.d/asterisk
/var/spool/mail/asterisk
/var/log/asterisk/full
/var/log/asterisk/dtmf
/var/log/asterisk/fail2ban
/var/log/asterisk/freepbx.log
/var/log/asterisk/freepbx_security.log 
/var/log/asterisk/freepbx_debug {
        size 50M
        missingok
        rotate 4
        #compress
        notifempty
        sharedscripts
        create 0640 asterisk asterisk
        postrotate
        /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null || true
        endscript
        su root root
}

Test ODBC

odbcinst -s -q

Use username & password in /etc/freepbx.conf to test connectivity to the DB via ODBC. 

isql -v MySQL-asteriskcdrdb someusername somepassword

Test asterisk ODBC access

asterisk -vvvr
CLI> odbc show

TFTP

If you plan to use hardware SIP phones you will probably want to enable the tftp server.

Create tftp configuration file.

nano /etc/xinetd.d/tftp
service tftp
{
protocol        = udp
port            = 69
socket_type     = dgram
wait            = yes
user            = nobody
server          = /usr/sbin/in.tftpd
server_args     = /tftpboot
disable         = no
}

Make the directory and restart the daemon to start tftp.

mkdir /tftpboot
chmod 777 /tftpboot
systemctl restart xinetd

Misc. settings

Set php memory limit and upload max file size.

sed -i 's/memory_limit = .*/memory_limit = 256M/g' /etc/php/7.4/apache2/php.ini
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 20M/g' /etc/php/7.4/apache2/php.ini
systemctl restart apache2

Disable and remove ufw firewall if it exists

systemctl disable ufw
systemctl stop ufw
apt purge ufw

Disable and remove apparmor if it exists

systemctl disable apparmor
systemctl stop apparmor
apt purge apparmor
Sections: