Freepbx on Debian (Debian v7, Asterisk v11, Freepbx v2.11)

Sections: 

Debian

This guide covers the installation of Asterisk and Freepbx from source on Debian v7.   Although Debian includes Asterisk deb packages they are not used in this guide.

 

Tested on:

Debian Wheezy v7.5
Asterisk v11.9
Freepbx v2.11

Let's get started

It is assumed you already have a server with a base Debian installation with no desktop environment before you begin. In other words you want to be running in console text mode not GUI graphics mode. If you already have a GUI installed you will probably want to disable it at boot time. 

This guide also assumes we are running as root (#) user and not a limited account ($) user.

Optionally edit /etc/default/grub and change  GRUB_CMDLINE_LINUX_DEFAULT=”quiet” to GRUB_CMDLINE_LINUX_DEFAULT=”” So we can see everything on the console during boot to watch for problems.

Update Grub:

After changes to etc/default/grub we need to update the grub config.

update-grub

Install Asterisk/Freepbx required packages, other useful packages, and their dependencies

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 tftpd postfix mailutils nano ntp chkconfig libspandsp-dev libcurl4-gnutls-dev unixodbc unixodbc-dev libmyodbc xinetd e2fsprogs linux-headers*

It will keep asking to set MySQL root password so set that now.  Configure postfix for internet site.

Install pear DB

Don't worry about the warning message.

pear install db-1.7.14

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
service xinetd restart

Set Timezone

check timezone

date

If it needs to be changed then do the following

dpkg-reconfigure tzdata

and follow instructions

Download and untar source files.

Get and install DAHDI (optional)

Not needed if you are not installing a telco card and not using meetme conferencing and paging.  Asterisk 11 uses confbridge by default for conferencing and paging.  If unsure then install anyways.

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 && make install && make config

Get Freepbx

Check if this is the latest released version.

cd /usr/src
wget http://mirror.freepbx.org/freepbx-2.11.0.tar.gz 
tar zxvf freepbx-2.11*

Get and Install Asterisk

Do NOT run make samples . It can cause problems that will have to be cleaned up later on.  If you run make samples during an upgrade of a running Freepbx system it will overwrite some Freepbx specific configs and break Freepbx. You will then have to manually change back user/password in /etc/asterisk/manager.conf if not using defaults.  There are misc. other problems that can come up as well.

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

Preinstall 

The CFLAGS=-mtune=native setting prevents some problems that come up with virtual machines and moving them to different hardware.  It is also arguably a better more compatible way to do it compared to the default Asterisk uses.  Last time we checked Asterisk uses CFLAGS=-march=native by default if nothing is specified.  Here is a link to the description of these settings.

cd /usr/src/asterisk-11*/
./configure CFLAGS=-mtune=native && make menuselect

Select format_mp3if doing anything with mp3.  Also select cdr_mysql.  Freepbx does not use Asterisk realtime but if you are thinking of using A2Billing then also select res_config_mysql.

Select Core Sounds and Extra Sounds.  I usually select ulaw in addition to gsm as they sound better.

Make sure to press the save button afterwards to save all the previous settings.

When you select format_mp3 above as an addon you must run a script otherwise the install will fail. 

cd /usr/src/asterisk-11*/
./contrib/scripts/get_mp3_source.sh

Compile and Install Asterisk 

DO NOT run make samples even though the install script suggests you do.  It can cause conflicts with Freepbx generated config files.

make && make install

Create Asterisk User

adduser asterisk --disabled-password --no-create-home --home /var/lib/asterisk --shell \
/sbin/nologin --gecos "Asterisk User"

Music on Hold

The Asterisk default moh directory is /moh and the Freepbx default moh directory is /mohmp3.  If we create a symbolic link everything is in one place and can still be found by both Freepbx and Asterisk.

ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3

Change Apache User

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. /var/lock/apache2
service apache2 restart

MySQL Setup

Mysql should already be running but just to be sure.

service mysql start

Configure the databases for Freepbx.  Since we have already created a mysql root password we have to enter this password after each of the following commands.

cd /usr/src/freepbx*/
mysqladmin -p create asterisk
mysqladmin -p create asteriskcdrdb
mysql -p asterisk < SQL/newinstall.sql
mysql -p asteriskcdrdb < SQL/cdr_mysql_table.sql
mysql -p

mysql> GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> \q

Install Freepbx

/usr/sbin/safe_asterisk

Now run the FreePBX install script.  Select all defaults for now by hitting the ENTER key at each prompt.

cd /usr/src/freepbx*/
./install_amp

If you get any warnings or errors they're usually not traumatic.

Set Freepbx to start on boot

nano /etc/rc.local

Add

/usr/local/sbin/amportal start

Before exit 0 

NOTE:  For Debian based Linux, Asterisk needs to recreate the /var/run/asterisk directory each time the server boots.  If you disabled quiet mode during boot you will see a warning to that effect on the console screen.

Set Apache root directory to /var/www/html

If this has already been changed from the default/var/www directory then edit manually

sed -i "s_/var/www_/var/www/html_" /etc/apache2/sites-available/default

Asterisk Manager Interface

AMI will not work on Debian 7 using the default freepbx /etc/asterisk/manager.conf file until these other 2 files are created as follows.
touch /etc/asterisk/manager_additional.conf
​touch /etc/asterisk/manager_custom.conf
reboot

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

After creating the default username/password, log into the FreePBX GUI and press the red Apply Config button at the top before doing anything else. This generates the Asterisk config files.   Asterisk will not run properly until these files are generated and the server rebooted.

reboot

This completes the mandatory part of this install guide.  The rest is optional depending on what you want to do.

We strongly suggest completing the logrotate section at a minimum.  If you don't do that the log files will continue to grow forever until your run out of disk space.  More recent versions of freepbx have a logfile module which will set this up for you. 

 

Optional Section

Logrotate

Set up configuration to rotate log files otherwise they get too big after a short while. Create the following file.

nano /etc/logrotate.d/asterisk

Now add the following to make sure the asterisk log files are rotated weekly along with all the other log files.

/var/log/asterisk/messages /var/log/asterisk/*log /var/log/asterisk/full {
missingok
notifempty
sharedscripts
create 0640 asterisk asterisk
postrotate
/usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
endscript
}

Do the same for freepbx

nano /etc/logrotate.d/freepbx
/var/log/asterisk/freepbx_dbug /var/log/asterisk/freepbx_debug {
missingok
notifempty
sharedscripts
create 0640 asterisk asterisk
postrotate
/usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
endscript
}

Configure voicemail to email template

nano etc/asterisk/vm_email.inc

Change the template to what you want the voicemail emails to look like.  Check that http://ipaddress_of_Freepbx_server is correct

CDR ODBC

This is optional if you selected the deprecated cdr_mysql module in Asterisk menu at compile time. This is the new recommended way of connecting to the CDR DB.  Eventually this will be required when cdr_mysql no longer works or is no longer included with Asterisk.

nano /etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/i386-linux-gnu/odbc/libmyodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1

If 64bit OS change the 1 line to ix86_64-linux-gnu Test that the ODBC driver is working

odbcinst -s -q

should result in [MySQL]

nano /etc/odbc.ini
[MySQL-asteriskcdrdb]
Description     = MySQL ODBC Driver
Driver          = MySQL
Socket          = /var/run/mysqld/mysqld.sock
Server          = localhost 
Database        = asteriskcdrdb 
Option          = 3

Check the following file which Asterisk uses to connect to the CDR DB

nano /etc/asterisk/res_odbc_additional.conf
[odbccdr]
enabled => yes 
dsn => MySQL-asteriskcdrdb 
username => asteriskuser 
password => amp109

Now using the above username/password, test that it can can connect to the DB via odbc

isql -v MySQL-asteriskcdrdb asteriskuser amp109

If you used a different username/password when setting up cdr DB use those and duplicate the res_odbc_addional.conf file to res_odbc_custom.conf substituting the username/password for the relevant ones. should result in

Connected!
sql-statement
help [tablename]
quit

SQL>

Type quitto exit.

Lastly create or add the following. Note connection=odbcdr matches [odbcdr] in res_odbc.conf.  calldate does not exist any more in cdr_adaptive_odbc.so.  To have the behaviour the same as standard cdr functions we add the alias start line

nano /etc/asterisk/cdr_adaptive_odbc.conf
[first]
connection=odbcdr
table=cdr
alias start => calldate

-------------------------------------------------------------------------

Misc. optional settings

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

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

Edit Apache web server for GUI access using a port other than 80:

nano +134 /etc/apache2/ports.conf

change "Listen 80" to "Listen 8888" or whatever port you want.  Instead of accessing FreePBX by http://xxx.xxx.xxx.xxx You now access it by http://xxx.xxx.xxx.xxx:8888 Change default Apache setting of AllowOverride None to All so that Apache obeys directives in .htaccess files which by default prevents viewing sensitive directories on Freepbx.

nano +7 /etc/apache2/sites-available/default
AllowOverride All
service apache2 restart

Setup external sip extensions if going through NAT.  You can also do this using Asterisk SIP Settings module.

nano /etc/asterisk/sip_nat.conf
nat=yes
externip= or
;externhost=yourdns.com
localnet=192.168.1.0/255.255.255.0
;change the above to whatever your local subnet is
externrefresh=10

(Ctrl-X>y>ENTER) Also, when adding the external SIP extension in FreePBX, make sure to change the nat=never default in the configuration to nat=yes for the extension that will be external.

Install FreePBX commercial module dependencies

NOTE:  You cannot currently install commercial modules on Debian 7 because it uses a newer version of PHP compared to the version the commercial modules were encoded for.  This information is provided only as a potential future reference.  

If you want to install commercial modules you need zendguard and some additional dependencies.

cd /usr/src

Download zendguard

For 32bit  wget http://downloads.zend.com/guard/6.0.0/ZendGuardLoader-70429-PHP-5.4-linux-glibc23-i386.tar.gz

For 64bit  wget http://downloads.zend.com/guard/6.0.0/ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz

Untar

tar -xzf ZendGuardLoader-70429-PHP-5.4*

Create directory for it and copy. 

mkdir /usr/local/lib/Zend
cp ZendGuardLoader-70429-PHP-5.4*/php-5.4.x/ZendGuardLoader.so /usr/local/lib/Zend/

Tell php where to find it.

nano /etc/php5/conf.d/zendguard.ini
zend_extension = /usr/local/lib/Zend/ZendGuardLoader.so
zend_loader.enable = 1

Install commercial module dependencies.

apt-get install -y incron prosody

 

Root alias

Edit /etc/aliases file and add an email address to forward ‘root’ messages to your personal email address.  At the very bottom you should see a commented example.  Copy it and replace with your email address

nano /etc/aliases
root:   some_email@somedomain.com

Then run

newaliases

Test if you can send emails via root

echo testing | mail -s "test mail" root@localhost

If you get an email then you know aliases and outbound email is working.

MySQL performance tuning

This will reduce memory usage without affecting performance.

nano /etc/mysql/my.cnf
[mysqld]
.
.
.
skip-innodb

(Ctl-x > y > ENTER) From command prompt:

service mysql restart

MySQL security enhancement

This will prevent outside IP's from connecting to MySQL.

nano /etc/mysql/my.cnf
[mysqld]
.
.
.
bind-address = 127.0.0.1

(Ctl-x > y > ENTER) From command prompt:

service mysql restart