Asterisk Freepbx on Debian (Debian v9, Asterisk v16, Freepbx v14)

Debian

 

 

This guide covers the installation of Asterisk v16 and Freepbx v14 GUI, from source, on Debian v9.  This procedure is similar to our Asterisk v13-15 on Freepbx v14 on Debian procedure and can be used to upgrade servers running that software.

Tested on

Debian v9 (Stretch) x64
Asterisk v16
Freepbx v14

Assumptions

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

Prerequisites

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

PHP

apt -y purge php* 
apt -y install curl apt-transport-https

curl https://packages.sury.org/php/apt.gpg | apt-key add -
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/deb.sury.org.list
apt -y update && apt -y install php5.6 php5.6-curl php5.6-cli php5.6-mysql php5.6-mbstring php5.6-gd php5.6-xml

Other initial dependencies

apt -y install 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 libsrtp0-dev unixodbc unixodbc-dev python-dev xinetd e2fsprogs dbus sudo xmlstarlet mongodb lame ffmpeg dirmngr linux-headers* 

Node.js

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

ODBC

Install ODBC Connector

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 = /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.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

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.

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-pjproject-bundled --with-jansson-bundled

To verify type nano -v config.log.

Set compile options

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

# Go to Applications 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/14.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
fwconsole chown
fwconsole reload

Optionally, install all modules (not recommended).  You will most likely 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
ExecStop=/usr/sbin/fwconsole stop
 
[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 {
        weekly
        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/asterisk/res_odbc_additional.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/5.6/apache2/php.ini
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 20M/g' /etc/php/5.6/apache2/php.ini
systemctl restart apache2
Sections: