Asterisk Freepbx on Debian (Debian v8, Asterisk v13, Freepbx v13)

Debian

This guide covers the installation of Asterisk and Freepbx from source on Debian v8. 

 

Tested on:

Debian v8 (Jessie)
Asterisk v13
Freepbx v13

Assumptions:

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

Install Prerequisites

apt-get update && apt-get upgrade -y
apt-get install -y build-essential openssh-server apache2 mysql-server mysql-client bison flex php5 php5-curl php5-cli php5-mysql php-pear php5-gd curl sox libncurses5-dev libssl-dev libmysqlclient-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git subversion uuid uuid-dev libiksemel-dev libjansson-dev tftpd postfix mailutils nano ntp chkconfig libspandsp-dev libcurl4-gnutls-dev unixodbc unixodbc-dev libmyodbc xinetd e2fsprogs dbus sudo linux-headers*

It will keep asking to set MySQL root password so set that now. 

Install legacy pear requirement

pear install Console_getopt

Set Timezone

Using tzselect is one way to find the correct timezone.

tzselect
## SET TIMEZONE EXAMPLE
timedatectl set-timezone America/Vancouver
​timedatectl status

Install

DAHDI

Only required if using a physical server and installing telecom hardware.

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

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

PJSIP

cd /usr/src
wget http://www.pjsip.org/release/2.5.5/pjproject-2.5.5.tar.bz2
tar -xjvf pjproject-2.5.5*
cd /usr/src/pjproject-2.5.5*/
make distclean
./configure --enable-shared --disable-sound --disable-resample \
--disable-video --disable-opencore-amr CFLAGS='-O2 -DNDEBUG'
make uninstall && ldconfig && make dep && make && make install && ldconfig

To verify type ldconfig -p | grep pj which should show several linked *.so files in /usr/local/lib.

Asterisk

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

To verify type nano -v config.log.

cd /usr/src/asterisk-13*/
make menuselect.makeopts

#To select compile options manually from menu run make menuselect instead of the following command.
#To list command line options run menuselect/menuselect --list-options
#If Asterisk fails to run on a virtual machine try add "--disable BUILD_NATIVE"
#To add asterisk realtime for applications such as A2billing add "--enable res_config_mysql"

menuselect/menuselect --enable cdr_mysql --enable EXTRA-SOUNDS-EN-GSM menuselect.makeopts

Create Asterisk User, compile, install and set ownership.

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

Freepbx

cd /usr/src
git clone -b release/13.0 --single-branch https://github.com/FreePBX/framework.git freepbx
cd /usr/src/freepbx
./start_asterisk start

## replace "somepassword" with the root password you assigned to MySQL
./install -n --dbpass somepassword
# Minimal module install
fwconsole ma upgrade framework core voicemail sipsettings infoservices \
featurecodeadmin logfiles callrecording cdr dashboard
fwconsole restart
fwconsole reload
fwconsole chown

Configure Apache

Change Apache run user and group name to asterisk.

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
systemctl restart apache2

Set Freepbx to start on boot

nano /etc/systemd/system/freepbx.service
​[Unit]
Description=Freepbx
After=mysql.service
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start
ExecStop=/usr/sbin/fwconsole stop
 
[Install]
WantedBy=multi-user.target

Now enable it.

systemctl enable freepbx
reboot

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

Post-install tasks are mandatory

Post-install tasks

Lock down the database server.

mysql_secure_installation

Enter root password and then 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/*log
/var/log/asterisk/messages
/var/log/asterisk/full
/var/log/asterisk/dtmf
/var/log/asterisk/freepbx_dbug
/var/log/asterisk/fail2ban {
        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
}

CDR ODBC

If the deprecated cdr_mysql.so module is installed then this is optional, but still recommended. 

nano /etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1
nano /etc/odbc.ini
[MySQL-asteriskcdrdb]
Description=MySQL connection to 'asteriskcdrdb' database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/run/mysqld/mysqld.sock
option=3

Test ODBC driver

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 freepbxuser 12e7c1f0c041ee853085624ec3bba112=

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

Change the “upload_max_filesize” from 2M to 20M to allow larger music on hold files.

nano +810 /etc/php5/apache2/php.ini

Add AllowOverride All under DocumentRoot so that .htaccess files in web folders are active.

nano +14 /etc/apache2/sites-available/000-default.conf
<Directory /var/www/html>
    AllowOverride All
    </Directory>
service apache2 restart

 

Sections: