Asterisk Freepbx on Debian (Debian v12, Asterisk v20, Freepbx v17)
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 fail2ban redis-server chrony incron software-properties-common python3-mysqldb default-libmysqlclient-dev
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 php8.2-redis php8.2-bz2 php8.2-ldap php8.2-bcmath php8.2-sqlite3 php-pear libapache2-mod-php
ODBC
Create /etc/odbcinst.ini
# Cut/paste the following lines into a Linux CLI cat > /etc/odbcinst.ini << EOF [MySQL] Description = ODBC for MariaDB Driver = libmaodbc.so FileUsage = 1 EOF
Create /etc/odbc.ini
# Cut/paste the following lines into a Linux CLI 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 existing 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
# Cut/paste the following lines into a Linux CLI 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.
# Cut/paste the following lines into a Linux CLI 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 a2enmod ssl
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.
Repository and commercial module support
# Cut/paste the following lines into a Linux CLI cat > /etc/apt/preferences.d/99sangoma-fpbx-repository << EOF # Always prefer packages from deb.freepbx.org Package: * Pin: origin deb.freepbx.org Pin-Priority: 600 EOF
# Cut/paste the following lines into a Linux CLI cat > /etc/apt/preferences.d/99freepbx17 << EOF # Prevent freepbx17 package from being installed over an existing freepbx 17 install and breaking things Package: freepbx17 Pin: release * Pin-Priority: -1 EOF
wget -qO - http://deb.freepbx.org/gpg/aptly-pubkey.asc | apt-key add add-apt-repository -y -S 'deb http://deb.freepbx.org/freepbx17-prod bookworm main' apt update && apt -y install ioncube-loader-82 systemctl restart apache2 apt -y install sysadmin17 sangoma-pbx17 asterisk-version-switch apt-mark hold sangoma-pbx17 fwconsole ma downloadinstall framework fwconsole reload
Switch from source-based to repo-based asterisk
Assuming repository support has already been installed
rm -rf /usr/lib/asterisk/modules sed -i 's#astmoddir => .*#astmoddir => /usr/lib/x86_64-linux-gnu/asterisk/modules#g' /etc/asterisk/asterisk.conf fwconsole setting ASTMODDIR /usr/lib/x86_64-linux-gnu/asterisk/modules asterisk-version-switch
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