Asterisk Freepbx on Debian (Debian v12, Asterisk v20, Freepbx v17)

Debian

 

 

This guide covers the installation of Asterisk v20 and Freepbx v17 from source on Debian v12.

Tested on

Debian v12 (Bookworm), x64 minimal install
Asterisk v20
Freepbx v17
PHP v8.2

Assumptions

Installation done as root user (su - )

Prerequisites

Verify locale is set to C.UTF-8 or en US.UTF-8.

locale

If it is not then set it now.  You may also set your own UTF-8 locale.

# Select C.UTF-8 UTF-8
apt update && apt -y install locales && dpkg-reconfigure locales

Log out/in or close/open shell for changes to take effect. 

Initial update

apt update && apt -y upgrade && reboot

Install base system

apt -y install locales sngrep build-essential net-tools aptitude openssh-server apache2 mariadb-server mariadb-client odbc-mariadb bison doxygen flex 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 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 xinetd e2fsprogs dbus sudo xmlstarlet lame ffmpeg dirmngr linux-headers-`uname -r` gnupg2 nodejs npm ipset incron

Install PHP

If php -v shows another version of PHP already installed then it should first be remove using apt purge php*.

apt -y install php8.2 php8.2-curl php8.2-cli php8.2-mysql php8.2-mbstring php8.2-gd php8.2-xml php8.2-intl php-pear libapache2-mod-php

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

Set Timezone

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

Install

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-20-current.tar.gz
tar zxvf asterisk-20-current.tar.gz
cd /usr/src/asterisk-20*/
./contrib/scripts/get_mp3_source.sh 
./contrib/scripts/install_prereq install
make distclean
./configure --with-jansson-bundled

To verify type nano -v config.log.

Set compile options.  Start here if recompiling with added/removed options.

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

# Select additional options if required
# 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:asterisk /var/lib/asterisk

Do not run the following command if FreePBX is already installed. It will overwrite /etc/asterisk/manager.conf which will break the install.

make samples

Freepbx

cd /usr/src
git clone -b release/17.0 --single-branch https://github.com/freepbx/framework.git freepbx
cd /usr/src/freepbx
./start_asterisk start
./install -n
fwconsole ma installall
fwconsole chown
fwconsole restart

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

Access GUI

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

Post-install tasks

Most post-install tasks are not mandatory, but highly recommended.

Commercial module support

IonCube loader must be installed if commercial modules are used.

cd /usr/src
wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar -xzf ioncube_loaders_lin_x86-64.tar.gz -C /usr/lib/php
nano /etc/php/8.2/mods-available/ioncube.ini
# Add the following line.
zend_extension = /usr/lib/php/ioncube/ioncube_loader_lin_8.2.so
# Create symlinks to loader
ln -s /etc/php/8.2/mods-available/ioncube.ini /etc/php/8.2/apache2/conf.d/00-ioncube.ini
ln -s /etc/php/8.2/mods-available/ioncube.ini /etc/php/8.2/cli/conf.d/00-ioncube.ini
systemctl restart apache2

php -v should now show that the ionCube Loader is installed.

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 5
        #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

Test driver

odbcinst -s -q

Test connectivity

# Extract variable values
USER="$(php -r 'include("/etc/freepbx.conf"); print $amp_conf["'AMPDBUSER'"];')"
PASS="$(php -r 'include("/etc/freepbx.conf"); print $amp_conf["'AMPDBPASS'"];')"

# Run command with extracted values
isql -v MySQL-asteriskcdrdb $USER $PASS

Test Asterisk ODBC access

asterisk -rx 'odbc show'

TFTP

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

apt install tftpd-hpa

Configure

nano /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa

TFTP_USERNAME="asterisk"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS=""

Make the directory and restart the daemon.

mkdir /tftpboot
chmod 777 /tftpboot
systemctl restart tftpd-hpa

Misc. settings

Set php memory limit and upload max file size.

sed -i 's/memory_limit = .*/memory_limit = 256M/g' /etc/php/8.2/apache2/php.ini
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 20M/g' /etc/php/8.2/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: