You are on page 1of 9

Asterisk & iVoipswitch Install Instructions

Install the dependencies for Asterisk and A2Billing:


yum -y install nano mysql mysql-server php phpmysql subversion httpd gcc gcc-c++ kerneldevel mlocate make openssl openssl-devel perl perl-Net-SSLeay perl-CryptSSLeay libtermcap-devel ncurses-devel doxygen curl-devel newtdevel mod_ssl crontabs vixie-cron speex speex-devel unixODBC unixODBCdevel libtool-ltdl libtool-ltdl-devel mysql-connector-odbc mysql mysqldevel php php-cli php-common php-gd php-pdo php-mbstring php-mcrypt flex
screen gcc gcc-c++ mod_ssl mysql mysql-develmysql-server build-essential
libxml2 libxml2-devel.i686 libuuid-devel.i686 sqlite-devel.i686 make
php.i686 php-devel
chkconfig httpd on
chkconfig mysqld on

Download and extract Asterisk and Asterisk-related files:


mkdir -p /usr/src/asterisk
cd /usr/src/asterisk
wget http://downloads.asterisk.org/pub/telephony/asterisk/oldreleases/asterisk-1.6.2.6.tar.gz
wget http://downloads.asterisk.org/pub/telephony/asterisk/oldreleases/asterisk-addons-1.6.2.1.tar.gz
wget http://downloads.asterisk.org/pub/telephony/dahdi-linuxcomplete/dahdi-linux-complete-current.tar.gz
wget http://downloads.digium.com/pub/libpri/libpri-1.4-current.tar.gz
tar
tar
tar
tar

-zxf
-zxf
-zxf
-zxf

asterisk-1.6.2.6.tar.gz
asterisk-addons-1.6.2.1.tar.gz
dahdi-linux-complete-current.tar.gz
libpri-1.4-current.tar.gz

Install Libpri
cd libpri-VERSION
make clean
make
make install

Install DAHDI
cd ..
cd dahdi-linux-complete-2.3.0.1+2.3.0
make all
make install
make config
service dahdi start

Have DAHDI load automatically upon system startup: chkconfig


Install Asterisk 1.6
cd ..
cd asterisk-1.6.2.6
make clean

dahdi on

./configure
make menuselect

A menu will come up. Usually everything by default is fine, however I would
also suggest installing the asterisk extras sound files in addition to the regular
sound files.
make
make
make
make
make

install
samples
progdocs
config

useradd -c "Asterisk PBX" -d /var/lib/asterisk asterisk


mkdir /var/run/asterisk
mkdir /var/log/asterisk
chown -R asterisk:asterisk /var/run/asterisk
chown -R asterisk:asterisk /var/log/asterisk
chown -R asterisk:asterisk /var/lib/php/session/
chkconfig asterisk on

OMIT THIS SCRIPT IF YOU WILL BE INSTALLING FREEPBX

Lets just make sure that Asterisk starts properly. Ignore the warnings:
asterisk -vvvvvvvvvvvvvvvvvvvc
core stop now

Install Asterisk Addons


cd ..
make clean
./configure
make menuselect

Voip-Info suggests not to install oh323, so remove that when the menu comes
up
make
make install
make samples

Set up MySQL
service mysqld start
mysql
CREATE USER 'asterisk'@'localhost' IDENTIFIED BY '9e4yb4GDHu5weHR498n';
GRANT FILE ON * . * TO 'asterisk'@'localhost' IDENTIFIED BY
'9e4yb4GDHu5weHR498n'
WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR
0 MAX_USER_CONNECTIONS 0 ;
GRANT INSERT ON `asterisk`.`cdr` TO 'asterisk'@'localhost';

(Replace 9e4yb4GDHu5weHR498n with your own password. All I did was randomly
type a whole bunch of stuff)
We need to edit the Asterisk related mysql configs to point to the right
database with the correct credentials

nano /etc/asterisk/cdr_mysql.conf

My global section looks like this. Adjust the password accordingly:


[global]
hostname=localhost
dbname=asterisk
table=cdr
password=9e4yb4GDHu5weHR498n
user=asterisk
port=3306
sock=/var/lib/mysql/mysql.sock
userfield=1
loguniqueid=yes

nano /etc/asterisk/res_mysql.conf
vi /etc/asterisk/res_config_mysql.conf(asterisk 11)
My general section looks like this. Adjust the password accordingly:
[general]
dbhost = localhost
dbname = asterisk
dbuser = asterisk
dbpass = 9e4yb4GDHu5weHR498n
dbport = 3306
dbsock = /var/lib/mysql/mysql.sock

Modify the way asterisk logs:


nano /etc/asterisk/logger.conf

Aside from the context names, make sure that this is the only string
uncommented. From what I remember, everything except the context names
were commented, so this will need to be uncommented:
full => notice,warning,error,debug,verbose

Now for what weve been waiting forA2Billing!


Download the A2Billing files using svn:
svn co --username guest --password guest
http://svn.a2billing.net/svn/asterisk2billing/tags/1current /usr/src/a2billing/
cd /usr/src/a2billing

Copy the files to the appropriate directories and set permissions


cp -r a2billing.conf /etc ;chmod 777 /etc/asterisk ;touch
/etc/asterisk/additional_a2billing_iax.conf ;touch
/etc/asterisk/additional_a2billing_sip.conf ;echo \#include
additional_a2billing_sip.conf >> /etc/asterisk/sip.conf;echo \#include
additional_a2billing_iax.conf >> /etc/asterisk/iax.conf ;chown
apache:apache /etc/asterisk/additional_a2billing_iax.conf ;chown

apache:apache /etc/asterisk/additional_a2billing_iax.conf
cd addons/sounds/
./install_a2b_sounds.sh
cd /usr/src/a2billing/AGI
cp -r a2billing.php /var/lib/asterisk/agi-bin/
cp -r lib/ /var/lib/asterisk/agi-bin/
chmod +x /var/lib/asterisk/agi-bin/a2billing.php
mkdir /var/www/html/a2billing
chown apache:apache /var/www/html/a2billing
cd ..
cp -r admin/ /var/www/html/a2billing
cp -r customer/ /var/www/html/a2billing
cp -r agent/ /var/www/html/a2billing
cp -r common/ /var/www/html/a2billing
cp -r webservice/ /var/www/html/a2billing
cd /var/www/html/a2billing/
chmod 777 /var/www/html/admin/templates_c/
chmod 777 /var/www/html/agent/templates_c/
chmod 777 /var/www/html/customer/templates_c/

Edit manager.conf to comply with VoIP Settings in the A2Billing UI


nano /etc/asterisk/manager.conf

Add the following:


[myasterisk]
secret = mycode
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read = system,call,log,verbose,command,agent,user
write = system,call,log,verbose,command,agent,user

Install the A2Billing Database


cd /usr/src/a2billing/DataBase/mysql-5.x

Start by creating the a2billing database and setting permissions


mysql
create database a2billingdb;
grant usage on *.* to a2buser@localhost identified by
'9e4yb4GDHu5weHR498n';
grant all privileges on a2billingdb.* to a2buser@localhost ;

Replace 9e4yb4GDHu5weHR498n with your own password and take note of


a2billingdb and a2buser. You can rename these two, just make sure to take
note of them.
The script below creates the A2Billing database. Use the database name, username and
password you just created in the previous step. When you are asked for the hostname,
type localhost

./install-db.sh

Edit a2billing.conf to match the database settings you just entered


nano /etc/a2billing.conf

In the database section, dbname should read the database name (a2billingdb),
user is the username you just created (a2user) and password is the password
you created. Everything else can stay as is.
Secure MySQL
Edit: nano /etc/my.cnf
Under the [mysqld] section, add:
bind-address = 127.0.0.1

Then restart MySQL: service

mysqld restart

Add appropriate contexts in extensions.conf


We need to add the a2billing contexts in the extensions.conf file. You will be
routing your inbound calls to these contexts accordingly. Add the following at
the end of the extensions.conf file:
[a2billing]
; VoIP customers live in this context by default
exten => _X.,1, DeadAGI(a2billing.php,1)
exten => _X.,n,Wait()
exten => _X.,n,Hangup()
[a2billing-cc]
; Inbound calls should be pointed here for Calling Card IVR. Dont forget
; to add a new agi-conf2 for calling card customers and adjust as desired.
exten => _X.,1,Answer
exten => _x.,n,Wait()
exten => _X.,n, DeadAGI(a2billing.php,2)
exten => _X.,n,Wait()
exten => _X.,n,Hangup()
[a2billing-did]

; This is where inbound DID calls are pointed to if you plan to be a DID
service provider
exten => _X.,1,DeadAGI(a2billing.php,1,did)
exten => _x,1,Hangup()

***On earlier versions of Asterisk 1.4 you will need to change the commas (,) to
bars (|)***
Add A2Billing cron schedules
A2Billing has many features such as currency updating, subscriptions, etc. In
order to automate all this we need to set a schedule.
Run this script. For some reason the cron jobs need
it: mkdir /var/run/a2billing
Type crontab -e and press i to insert data. Paste the following:
# update the currency table
0 6 * * * php /usr/src/a2billing/Cronjobs/currencies_update_yahoo.php
# manage the monthly services subscription
0 6 1 * * php /usr/src/a2billing/Cronjobs/a2billing_subscription_fee.php
# To check account of each Users and send an email if the balance is
#less than the user have choice.
0 * * * * php /usr/src/a2billing/Cronjobs/a2billing_notify_account.php
# this script will browse all the DID that are reserve and check if
#the customer need to pay for it
# bill them or warn them per email to know if they want to pay in
#order to keep their DIDs
0 2 * * * php /usr/src/a2billing/Cronjobs/a2billing_bill_diduse.php
# This script will take care of the recurring service.
0 12 * * * php /usr/src/a2billing/Cronjobs/a2billing_batch_process.php
# To generate invoices and for each user.
0 6 * * * php /usr/src/a2billing/Cronjobs/a2billing_batch_billing.php
# to proceed the autodialer
*/5 * * * * php /usr/src/a2billing/Cronjobs/a2billing_batch_autodialer.php
# manage alarms
0 * * * * php /usr/src/a2billing/Cronjobs/a2billing_alarm.php

Type :w to save, followed by :q to quit

We now need to install PHP 5.2 to ensure we get A2Billing working to its full
ability. PHP 5.2 isnt officially released for CentOS yet, so we need to be
careful. Also note that PHP 5.3 is NOT compatible with A2Billing as of yet.

Create a new repo:


nano -w /etc/yum.repos.d/centostesting.repo

Add the following:


[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
includepkgs=php*

Lets perform a yum update for PHP:


yum --enablerepo=c5testing update php*

Confirm that the packages about to be upgraded will be upgraded to PHP 5.2
and continue with the upgrade. I will need to update this article if PHP 5.3+
enters the repo and A2Billing still does not support it. Please contact me if this
happens.
One last thing we want to do is edit php.ini to allow for greater file uploading.
This will help us when we make rate decks.
nano +573 /etc/php.ini

Change: upload_max_filesize

= 2M

to:
upload_max_filesize = 12M

12 MB should be sufficient. We will need to adjust this in the A2Billing UI as


well.
Before we reboot, lets just set up IP tables to allow traffic into A2Billing and
open up the VoIP ports. I prefer to use SSL for web interface access (port 443)
but if you REALLY want to use HTTP, change 443 to 80. Note that if you are
using PayPal, port 443 is required to be open:
iptables
iptables
iptables
iptalbes

-A
-A
-A
-A

INPUT
INPUT
INPUT
INPUT

-p
-p
-p
-p

udp
udp
udp
tcp

-m
-m
-m
-r

udp --dport 5060 -j ACCEPT


udp --dport 10000:20000 -j ACCEPT
udp --dport 4569 -j ACCEPT
-m tcp -r --dport 443 -j ACCEPT

iptalbes -A INPUT -p tcp -r -m tcp -r --dport 80 -j ACCEPT


service iptables save

Ok, lets reboot the server now. Upon startup, try accessing A2Billing by going
to https://SERVER-IP/abilling/admin Note: HTTPS

Username: root
Password: changepassword
Credentials are case sensitive
Once you can get in, go to System Settings, Global List. Under
the webui section, edit my_max_file_size_import and change the value
to 12582912
We need to set this up in the PHP config file too.
nano +582 /etc/php.ini

The upload_max_filesize should read as follows:


upload_max_filesize = 12M

Followed by:

service httpd restart

In the Global List settings you also want to configure the way your calling card
or VoIP service works. Each agi-conf gives different settings. The purpose
of agi-conf is to control the call in progress. For instance, if you want to use
your system for VoIP least cost routing and for calling cards, the calling cards
would use one agi-conf and the VoIP stuff would use another.
Inextensions.conf under the a2billing sample contexts we created, you will see
a2billing.php,1. The number 1 represents the agi-conf to point to. You usually
want to point DIDs to agi-conf 1 and set this config to not answer calls, this
way you are not charged for ringing. You need to build the agi-conf and
configure it accordingly. It is safe to play around with the agi-conf. The setting
forpinless dialing is cid_enable. For DIDs you want to make sure
that use_dnid is enabled.

cd /usr/src/a2billing/AGI
cp -r a2billing.php /var/lib/asterisk/agi-bin/
cp -r lib/ /var/lib/asterisk/agi-bin/
chmod +x /var/lib/asterisk/agi-bin/a2billing.php
mkdir /var/www/html/a2billing
chown apache:apache /var/www/html/a2billing
cd ..
cp -r admin/ /var/www/html/a2billing/
cp -r customer/ /var/www/html/a2billing/
cp -r agent/ /var/www/html/a2billing/
cp -r common/ /var/www/html/a2billing/
cp -r webservice/ /var/www/html/a2billing/
cd /var/www/html/a2billing/
chmod 777 /var/www/html/a2billing/admin/templates_c/
chmod 777 /var/www/html/a2billing/agent/templates_c/
chmod 777 /var/www/html/a2billing/customer/templates_c/

database-a2billingdb
user--a2buser
pwd--fiyu@1

You might also like