Creating a VOIP Server with Asterisk and FreePBX

Author: Stephen Hinton

Credit to: http://blog.keer.info/debian-asterisk-freepbx-complete-installation-guide/ for making the guide which this is based upon. The goal of this page is to provide an updated guide specifically for our platform.

Introduction

This guide will outline the steps of installing asterisk, freepbx and all required packages on a DebWrt system. This guide was made with Wheezy but should also work for Squeeze and others.

Prerequisites

Compiler and Package Requirements

apt-get install kernel-package make g++ libncurses5-dev libxml2 libxml2-dev libtiff4 libtiff4-dev apache2 libapache2-mod-php5 php5-mysql php5-gd php-pear mysql-server openssl libssl-dev bison libaudiofile-dev curl sox sudo unixodbc-dev libmyodbc subversion libmysqlclient-dev libsqlite3-dev libsnmp-dev

Linux Source - If you built DebWrt from SVN *Recommended*

Copy the linux source folder to the /usr/src directory on your debwrt usb device.

On your development computer:

*Assuming brcm47xx, your debwrt usb device is mounted at /media/DEBWRT_ROOT and kernel version 3.3.8. Adjust for your environment

cp -r /home/username/debwrt/build/openwrt-brcm47xx-Broadcom-b43-trunk-HEAD-default/build_dir/linux-brcm47xx/linux-3.3.8 /media/DEBWRT_ROOT/usr/src/
ln -s /media/DEBWRT_ROOT/usr/src/linux-3.3.8 /media/DEBWRT_ROOT/usr/src/linux

On the router:

cd /usr/src/linux/
yes "" | make oldconfig
make prepare
make prepare scripts

Linux Source - If you installed by some other method

apt-get install linux-source-2.6
cd /usr/src/
tar xvjf /usr/src/linux-source-2.6.XX.tar.bz2
ln -s /usr/src/linux-source-2.6.XX /usr/src/linux
cd /usr/src/linux/
yes "" | make oldconfig
make prepare
make prepare scripts

Lame encoder

echo ìdeb http://www.deb-multimedia.org squeeze main non-freeî >> /etc/apt/sources.list
cd /tmp
wget ìhttp://deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2012.05.10-dmo3_all.debî -O /tmp/deb-multimedia-keyring_2012.05.10-dmo3_all.deb
dpkg -i /tmp/deb-multimedia-keyring_2012.05.10-dmo3_all.deb
apt-get update
apt-get install lame libmp3lame-dev

Optional Software

Depending on your needs, you can install Dahdi, Zaptel and libpri during this step. This will not be covered in this guide as we are assuming sip is being utilized for all trunks on a router.

Asterisk

cd /usr/src/
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.8-current.tar.gz
tar zxvf asterisk-1.8-current.tar.gz
cd /usr/src/asterisk-<version>/
./contrib/scripts/get_mp3_source.sh
./configure
make menuconfig
make
make install
make samples

When running make menuconfig above select:

app_mysql, app_saycountpl, cdr_mysql, format_mp3, res_config_mysql, EXTRAS-SOUNDS-EN-GSM

If you are feeling adventurous you can also select the "Low Memory" option under compiler flags. Warning: this can be unstable.

If you wish to use Asterisk 10 see the section below

You will still need to install asterisk 1.8 first and then upgrade due to a bug in FreePBX.

FreePBX and LAMP Stack

Apache2

sed -i "s/\(upload_max_filesize *= *\)\(.*\)/\120M/" /etc/php5/apache2/php.ini
sed -i "s/\(memory_limit *= *\)\(.*\)/\1100M/" /etc/php5/apache2/php.ini

*While memory limit is quite high for a router, freepbx will complain if this value is any lower.

MySql/Users? and Groups

Adding user and group for asterisk

groupadd asterisk
useradd -c "asterisk PBX" -d /var/lib/asterisk -g asterisk asterisk

Creating databases and database users

mysql -u root -p
*Enter Password*
create database asteriskcdrdb;
create database asterisk;
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
quit;

FreePBX

cd /usr/src/
wget http://mirror.freepbx.org/freepbx-2.9.0.tar.gz
tar zxvf freepbx-2.9.0.tar.gz
cd /usr/src/freepbx-2.9.0/

Freepbx and asterisk tables creation

mysql -u asteriskuser -pamp109 asteriskcdrdb < /usr/src/freepbx-2.9.0/SQL/cdr_mysql_table.sql
mysql http://dev.debwrt.net/wiki/DocNetUserVoip#-u asteriskuser -pamp109 asterisk < /usr/src/freepbx-2.9.0/SQL/newinstall.sql

FreePBX installation (Finally!)

/usr/src/freepbx-2.9.0/start_asterisk start
pear install DB
/usr/src/freepbx-2.9.0/install_amp

Enter your ip address when asked and change your webroot to "/var/www". Leave the rest of the options as default.

If you instead wish to install FreePBX 2.10 you must install 2.90 first! There is a bug in the install script which will cause installation to fail at the time of writing

Now that the installation is done change apache2 to run as the asterisk user *required*

sed -i "s/\(^User *\)\(.*\)/\1asterisk/" /etc/apache2/apache2.conf
sed -i "s/\(^Group *\)\(.*\)/\1asterisk/" /etc/apache2/apache2.conf
service apache2 restart

*For a low meory tuned configuration of mysql/apache2, see the attached files "my.cnf and apache2.conf below and replace existing files.

Now go to "http://your_router_ip_address/admin", log in with "admin, admin" and click Apply configuration changes.

FreePBX is now installed!

Create a startup script

cd /etc/init.d
vi amportal-startup

*insert the following and save

#!/bin/sh
# /etc/init.d/amportal-startup
#
 
### BEGIN INIT INFO
# Provides:          Asterisk
# Required-Start:    $remote_fs $syslog $all
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Asterisk at boot time
# Description:       Enable Asterisk.
### END INIT INFO
 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
 
export PATH
 
case "$1" in
  start)
        amportal start
    ;;
  stop)
        amportal stop
    ;;
  *)
    echo "Usage: /etc/init.d/amportal-startup {start|stop}"
    exit 1
    ;;
esac
 
exit 0

Make it executable and install

chmod +x amportal-startup
insserv amportal-startup

Change default passwords

Change password to whatever you like, this will change the sql and asterisk manager passwords for security

NEWPASSWORD='password';

then...

sed -i "s/\(^AMPDBPASS=*\)\(.*\)/\1$NEWPASSWORD/" /etc/amportal.conf
sed -i "s/\(^password = *\)\(.*\)/\1$NEWPASSWORD/" /etc/asterisk/cdr_mysql.conf
sed -i "s/\(^AMPDBPASS = *\)\(.*\)/\1$NEWPASSWORD/" /etc/asterisk/extensions_additional.conf
sed -i "s/\($amp_conf\['AMPDBPASS'\]\\t= '*\)\(.*\)/\1$NEWPASSWORD';/" /etc/freepbx.conf
sed -i "s/\(^secret = *\)\(.*\)/\1$NEWPASSWORD/" /etc/asterisk/manager.conf
sed -i "s/\(^AMPMGRPASS = *\)\(.*\)/\1$NEWPASSWORD/" /etc/asterisk/extensions_additional.conf
sed -i "s/\(^AMPMGRPASS=*\)\(.*\)/\1$NEWPASSWORD/" /etc/amportal.conf
asterisk -r -x "module reload manager"
echo "SET PASSWORD FOR 'asteriskuser'@'localhost' = PASSWORD('$NEWPASSWORD');" | mysql -u root -p
echo "UPDATE freepbx_settings SET value='$NEWPASSWORD' WHERE keyword='AMPMGRPASS';" | mysql -u root -p asterisk

Now reboot!

Using Asterisk 10

If you wish to use asterisk 10 you must complete the following steps:

Remove existing asterisk modules and backup if you like.

Download asterisk 10 source, configure, make menuconfig (same options as above), make, make install. DO NOT RUN "make samples" as this will overwrite necessary files!

FreePBX 2.90 does not support Asterisk 10 so you must upgrade this as well

Download FreePBX 2.10 source and install using same method as above except replacing "/usr/src/freepbx-2.9.0/start_asterisk start" with "amportal start".

Downloadable Files

*Will be uploaded shorty [] []

Last modified 4 years ago Last modified on Nov 4, 2012, 1:32:45 AM