***UPDATE*** Asterisk, FreePBX 2.8.1, HylaFAX 6.0.5, AvantFAX 3.3.3, IAXModem 1.2.0, A2Billing 1.9.4 ***WORKING***

Here is the code I used to setup Asterisk on CentOS 6 i386 with FreePBX, Hylafax, Avantfax, IAXModem, and A2billing

If you have any questions or comments please leave a comment or contact me directly email admin at 2000matrix dot com or call 413-285-3050


A2Billing Working Example, US Calling ONLY
Access# 413-206-9861
PIN# 4320101553

IAXModem Fax over IP, Receive Line Only
Fax# 413-455-0155

Asterisk Incoming Line, Live Line
Access# 413-285-3050

#CentOS 6 Asterisk PHP 5.3.2


#Install New Kernel < 4GB Ram
yum -y install kernel kernel-devel kernel-headers system-config*

Install New Kernel > 4GB Ram
yum -y install kernel-PAE kernel-PAE-devel system-config*

#Firewall & Network Settings

#Install Asterisk Dependencies
yum install -y make nano mgetty mgetty-voice cups-lpd perl-DBD-Pg subversion wget python python-devel glibc glibc-devel gcc gcc-c++ flex screen sox libxml2-devel libxml2 yum-utils ncurses-devel subversion libtiff libtiff-devel libusb-devel bison bison-devel ncurses ntp zlib zlib-devel openssl openssl-devel gnutls-devel httpd bind ghostscript-devel speex-devel libogg-devel libvorbis-devel curl-devel unixODBC-devel libtool-ltdl-devel net-snmp-devel bzip2-devel newt-devel lm_sensors-devel openldap-devel postgresql-devel gtk±devel libtermcap termcap webalizer expect sendmail-cf ImageMagick ImageMagick-devel ghostscript libtiff netpbm-progs libungif cups lpr psutils libc-client dovecot java-1.6.0-openjdk java-1.6.0-openjdk-devel php php-devel php-common php-mysql php-pdo php-soap php-xml php-xmlrpc php-mbstring php-gd php-pear php-process php-imap mysql mysql-devel mysql-server php-mysql mysql-libs libmysqlclient15 mysql-connector-odbc memcached php-pecl-memcache php-adodb

#Ghostscript Fonts Fix
cd /usr/src
wget http://ghostscript.googlecode.com/files/ghostscript-fonts-std-8.11.tar.gz
tar zxf ghostscript-fonts-std-8.11.tar.gz
mv fonts/ /usr/share/ghostscript/
nano /usr/share/ghostscript/8.70/Resource/Init/Fontmap.GS

/Courier-Bold (n022004l.pfa) ;

#Add Asterisk User
useradd -c “Asterisk PBX” -d /var/lib/asterisk asterisk

#Install Webmin Development
cd /usr/src
wget http://download.webmin.com/devel/rpm/webmin-1.571-1.noarch.rpm
wget http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

rpm -ivh webmin-1.571-1.noarch.rpm
rpm -ivh epel-release-6-5.noarch.rpm
rpm -ivh remi-release-6.rpm


cd /usr/src
wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
sh setuptools-0.6c11-py2.6.egg

#Install libpri
cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/libpri/releases/libpri-1.4.12.tar.gz
tar zxf libpri-1.4.12.tar.gz
cd libpri-1.4.12
make && make install

#Install DAHDI
cd …
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux/releases/dahdi-linux-
tar zxf dahdi-linux-
cd dahdi-linux-
make && make install

cd …
wget http://downloads.asterisk.org/pub/telephony/dahdi-tools/releases/dahdi-tools-
tar zxf dahdi-tools-
cd dahdi-tools-
./configure && make && make install && make config

#Setup Asterisk directories and startup files
mkdir -p /var/lib/digium/licenses/
chown asterisk /var/lib/php/session/
mkdir -p /etc/udev/permissions.d/
chkconfig --add dahdi
/etc/init.d/dahdi start
chkconfig --add httpd
/etc/init.d/httpd start
chkconfig --add named
/etc/init.d/named start
chkconfig --add mysqld
/etc/init.d/mysqld start

#Install more Dependencies for Asterisk
cd …
wget http://asterisk.gnuinter.net/files/asterisk-perl-1.01.tar.gz
tar zxf asterisk-perl-1.01.tar.gz
cd asterisk-perl-1.01
perl Makefile.PL
make all
make install

cd …
wget http://mpg123.de/download/mpg123-1.13.4.tar.bz2
tar jxf mpg123-1.13.4.tar.bz2
cd mpg123-1.13.4
./configure && make && make install

cd …
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.1.tar.gz
tar zxf lame-3.99.1.tar.gz
cd lame-3.99.1
./configure && make && make install

cd …
wget http://iksemel.googlecode.com/files/iksemel-1.4.tar.gz
tar zxf iksemel-1.4.tar.gz
cd iksemel-1.4
./configure && make && make install

echo “/usr/local/lib” > /etc/ld.so.conf.d/iksemel.conf

#Install Secure RTP Communications
cd …
wget http://downloads.sourceforge.net/project/srtp/srtp/1.4.4/srtp-1.4.4.tgz
tar zxf srtp-1.4.4.tgz
cd srtp
./configure && make && make install

#Install Fax Capability
cd …
wget http://soft-switch.org/downloads/spandsp/spandsp-0.0.6pre18.tgz
tar zxf spandsp-0.0.6pre18.tgz
cd spandsp-0.0.6
./configure --prefix=/usr && make && make install

cd …
wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-
tar zxf asterisk-
cd asterisk-
make menuconfig

app_mysql, app_saycountpl, cdr_mysql, format_mp3, res_config_mysql, res_srtp

make && make install

#Install g729 Codec

#For Server
cd /usr/lib/asterisk/modules
cat /proc/cpuinfo
wget -O codec_g723.so http://asterisk.hosting.lv/bin/codec_g723-ast18-gcc4-glibc-core2.so
wget -O codec_g729.so http://asterisk.hosting.lv/bin/codec_g729-ast18-gcc4-glibc-core2.so
chmod +x codec_g723.so
chmod +x codec_g729.so

#Install FreePBX
cd /usr/src
wget http://mirror.freepbx.org/freepbx-2.8.1.tar.gz
tar zxf freepbx-2.8.1.tar.gz
cd freepbx-2.8.1
mysqladmin create asterisk
mysqladmin create asteriskcdrdb
mysql asterisk < SQL/newinstall.sql
mysql asteriskcdrdb < SQL/cdr_mysql_table.sql
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO [email protected] IDENTIFIED BY ‘changepassword’;
GRANT ALL PRIVILEGES ON asterisk.* TO [email protected] IDENTIFIED BY ‘changepassword’;
flush privileges;
pear channel-update pear.php.net
pear install DB MDB2 MDB2#mysql
mkdir -p /var/lib/asterisk/run

#Fix Asterisk Music On Hold
ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3

#Install FreePBX
cd /usr/src/freepbx-2.8.1

setenforce 0

#Username asterisk Password changepassword
#Change httpd apache user to asterisk

chmod 777 /etc/amportal.conf
cd /var/lib/asterisk
chown -R asterisk:asterisk *
chmod -R 777 *
cd /var/www/html
chown -R asterisk:asterisk *
chmod -R 777 *
chown -R asterisk:asterisk /var/lib/php/session
chown -R asterisk:asterisk /var/spool/asterisk/*

#Edit Asterisk IAX2 Settings Add Other Options in FreePBX
calltokenoptional =
maxcallnumbers = 16382
requirecalltoken = no

#Asterisk Settings for a2billing
nano /etc/asterisk/cdr_mysql.conf

hostname = localhost
password = changepassword
user = asterisk

nano /etc/asterisk/res_mysql.conf

dbhost = localhost
dbname = a2billing
dbuser = root
dbpass =
dbport = 3306
dbsock = /var/lib/mysql/mysql.sock

#A2Billing Installation
cd /usr/src
mkdir a2billing
cd a2billing
wget --no-check-certificate https://github.com/Star2Billing/a2billing/tarball/v1-current
tar zxf v1-current
cd Star2Billing-a2billing-*
mv * …
cd …
rm -rf Star2Billing-a2billing-*
ln -s /usr/src/a2billing/a2billing.conf /etc/a2billing.conf
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_custom.conf
echo #include additional_a2billing_iax.conf >> /etc/asterisk/iax_custom.conf
chown asterisk:asterisk /etc/asterisk/additional_a2billing_iax.conf
chown asterisk:asterisk /etc/asterisk/additional_a2billing_iax.conf
cd addons/sounds/
ln -s /usr/src/a2billing/AGI/a2billing.php /var/lib/asterisk/agi-bin/a2billing.php
ln -s /usr/src/a2billing/AGI/lib/ /var/lib/asterisk/agi-bin/
chmod +x /var/lib/asterisk/agi-bin/a2billing.php
ln -s /usr/src/a2billing/customer/ /var/www/html/billing
ln -s /usr/src/a2billing/admin/ /var/www/html/billing
ln -s /usr/src/a2billing/agent/ /var/www/html/billing
ln -s /usr/src/a2billing/common/ /var/www/html/billing
chmod 777 /var/www/html/billing/admin/templates_c/
chmod 777 /var/www/html/billing/agent/templates_c/
chmod 777 /var/www/html/billing/templates_c/

nano /etc/asterisk/manager.conf

[myasterisk] ;FOR a2billing
secret = mycode
read = system,call,log,verbose,command,agent,user
write = system,call,log,verbose,command,agent,user

#Install Database for A2Billing
cd /usr/src/a2billing/DataBase/mysql-5.x
mysqladmin create a2billing
GRANT ALL PRIVILEGES ON a2billing.* TO [email protected] IDENTIFIED BY ‘changepassword’;
flush privileges;

#USE a2billing/changepassword

#Secure MySQL
nano /etc/my.cnf

bind-address =

nano /etc/asterisk/extensions_custom.conf

; Set by Network staff for manual assignment
exten => _X.,1,AGI(a2billing.php,1)
exten => _X.,n,Wait()
exten => _X.,n,Hangup()

; Used by Calling Card Platform for incoming calls
exten => _X.,1,AGI(a2billing.php,2)
exten => _X.,n,Wait()
exten => _X.,n,Hangup()

; Set by website signup for automatic assignment
exten => _X.,1,AGI(a2billing.php,3)
exten => _X.,n,Wait()
exten => _X.,n,Hangup()

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

exten => s,1,GotoIf($["${OUT_${DIAL_TRUNK}:4:4}" = “A2B/”]?custom-freepbx-a2billing,${OUTNUM},1:2)
exten => s,2,MacroExit

exten => X.,1,AGI(a2billing.php|${OUT${DIAL_TRUNK}:8})
exten => _X.,n,Hangup()

mkdir /var/run/a2billing


crontab -e

update the currency

0 6 * * * php /usr/src/a2billing/Cronjobs/currencies_update_yahoo.php

monthly services subscription

0 6 1 * * php /usr/src/a2billing/Cronjobs/a2billing_subscription_fee.php

check account of users

0 * * * * php /usr/src/a2billing/Cronjobs/a2billing_notify_account.php

did billing

0 2 * * * php /usr/src/a2billing/Cronjobs/a2billing_bill_diduse.php

recurring service.

0 12 * * * php /usr/src/a2billing/Cronjobs/a2billing_batch_process.php

generate invoices and for each user.

0 6 * * * php /usr/src/a2billing/Cronjobs/a2billing_batch_billing.php


*/5 * * * * php /usr/src/a2billing/Cronjobs/a2billing_batch_autodialer.php

manage alarms

0 * * * * php /usr/src/a2billing/Cronjobs/a2billing_alarm.php


mkdir -p /var/lib/a2billing/script
touch /var/log/asterisk/a2billing-daemon-callback.log
touch /var/log/a2billing-daemon-callback.log
touch /var/log/cront_a2b_alarm.log
touch /var/log/cront_a2b_autorefill.log
touch /var/log/cront_a2b_batch_process.log
touch /var/log/cront_a2b_bill_diduse.log
touch /var/log/cront_a2b_subscription_fee.log
touch /var/log/cront_a2b_currency_update.log
touch /var/log/cront_a2b_invoice.log
touch /var/log/a2billing_paypal.log
touch /var/log/a2billing_epayment.log
touch /var/log/api_ecommerce_request.log
touch /var/log/api_callback_request.log
touch /var/log/a2billing_agi.log
easy_install sqlalchemy
cd $LOAD_LOC/CallBack/callback-daemon-py/
cp $LOAD_LOC/CallBack/callback-daemon-py/build/lib/callback_daemon/a2b-callback-daemon.rc /etc/init.d/a2b-callback-daemon
chmod +x /etc/init.d/a2b-callback-daemon
python setup.py build
python setup.py bdist_egg
easy_install dist/callback_daemon-1.0.prod-py2.6.egg

chkconfig --add a2b-callback-daemon
service a2b-callback-daemon start
chkconfig a2b-callback-daemon on

#FreePBX Custom Destinations in /etc/asterisk/extensions_custom.conf
Custom Destination: a2billing,${EXTEN},1
Description: a2billing

Custom Destination: a2billing-callback,${EXTEN},1
Description: a2billing-callback

Custom Destination: a2billing-cid-callback,${EXTEN},1
Description: a2billing-cid-callback

Custom Destination: a2billing-did,${EXTEN},1
Description: a2billing-did

Custom Destination: a2billing-sip,${EXTEN},1
Description: a2billing-sip

Custom Destination: a2billing-cc,${EXTEN},1
Description: a2billing-cc

Custom Destination: a2billing-passthrough,${EXTEN},1
Description: a2billing-passthrough

#Install Tesseract
cd /usr/src
wget http://www.leptonica.com/source/leptonica-1.68.tar.gz
tar zxf leptonica-1.68.tar.gz
cd leptonica-1.68
./configure && make && make install

cd …
wget http://tesseract-ocr.googlecode.com/files/tesseract-3.00.tar.gz
tar zxf tesseract-3.00.tar.gz
cd tesseract-3.00
./configure && make && make install

#Install IAXModem
cd /usr/src
wget http://downloads.sourceforge.net/project/iaxmodem/iaxmodem/iaxmodem-1.2.0/iaxmodem-1.2.0.tar.gz
tar zxf iaxmodem-1.2.0.tar.gz
cd iaxmodem-1.2.0
./build static
mkdir -p /etc/iaxmodem
mkdir -p /var/log/iaxmodem
cp iaxmodem /usr/local/sbin/

nano /etc/iaxmodem/ttyIAX1

device /dev/ttyIAX1
owner uucp:uucp
mode 660
port 4570
refresh 300
peername 111
secret 111password
codec ulaw
cidname Fax
cidnumber 4132853050

#Install Hylafax
cd …
wget ftp://ftp.hylafax.org/source/hylafax-6.0.5.tar.gz
tar zxf hylafax-6.0.5.tar.gz
cd hylafax-6.0.5

make install

service hylafax restart

nano /var/spool/hylafax/etc/config.ttyIAX1

CountryCode: 1
AreaCode: 413
FAXNumber: 1.413.285.3050
LongDistancePrefix: 1
InternationalPrefix: 011
DialStringRules: "etc/dialrules"
ServerTracing: 1
SessionTracing: 1
RecvFileMode: 0600
LogFileMode: 0600
DeviceMode: 0600
RingsBeforeAnswer: 1
SpeakerVolume: off
GettyArgs: "-h %l dx_%s"
LocalIdentifier: "WTN"
TagLineFont: etc/lutRS18.pcf
TagLineFormat: "From %%l|%c|Page %%P of %%T"
MaxRecvPages: 200
JobReqNoCarrier: 180
JobReqNoAnswer: 180
FaxRcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
NotifyCmd: bin/notify.php
ModemType: Class1 # use this to supply a hint
ModemResetCmds: “ATH1\nAT+VCID=1” # enables CallID display
ModemReadyCmds: ATH0
Class1AdaptRecvCmd: AT+FAR=1
Class1TMConnectDelay: 400 # counteract quick CONNECT response
Class1RMQueryCmd: “!24,48,72,96” # V.17 fast-train recv doesn’t work well
Class1TMQueryCmd: “!24,48,72,96” # V.17 fast-train recv doesn’t work well
CallIDPattern: "NMBR="
CallIDPattern: "NAME="
CallIDPattern: "ANID="
CallIDPattern: “NDID=”

cd /var/spool/hylafax/etc
chown uucp:uucp config.ttyIAX1

#Edit HylaFAX Verticle Resolution
nano /usr/local/lib/fax/hyla.conf

JobFmt: "%-5j %1a %15o %-15.15e %5P %5D %5i %7z %.25s"
RcvFmt: "%7o %-10t %-25s %-20f %5p %1z %-40e"
PageSize: na-let
VRes: 196

faxadduser -a changepassword asterisk
faxdeluser localhost
echo >> /var/spool/hylafax/etc/hosts.hfaxd

nano /etc/init/faxgetty1.conf

start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
exec /usr/local/sbin/faxgetty ttyIAX1

nano /etc/init/faxgetty2.conf

start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
exec /usr/local/sbin/faxgetty ttyIAX2

nano /etc/init/iaxmodem1.conf

start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
exec /usr/local/sbin/iaxmodem ttyIAX1

nano /etc/init/iaxmodem2.conf

start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
exec /usr/local/sbin/iaxmodem ttyIAX2

nano /etc/rc.local

/usr/local/sbin/amportal start
initctl start faxgetty1
initctl start faxgetty2
initctl start faxgetty3
initctl start faxgetty4
initctl start iaxmodem1
initctl start iaxmodem2
initctl start iaxmodem3
initctl start iaxmodem4

#Install AvantFAX
cd /usr/src
wget http://downloads.sourceforge.net/project/avantfax/avantfax-3.3.3.tgz
tar zxf avantfax-3.3.3.tgz
cd avantfax-3.3.3
chown -R asterisk:asterisk *
cd avantfax
ln -s /usr/src/avantfax-3.3.3/avantfax /var/www/html/fax
chown -R asterisk:asterisk /var/www/html/fax
chmod -R 0770 /var/www/html/fax/tmp /var/www/html/fax/faxes
chown -R asterisk:uucp /var/www/html/fax/tmp /var/www/html/fax/faxes
chown -R asterisk:asterisk /var/lib/php/session
mv /usr/local/bin/faxcover /usr/local/bin/faxcover.old
ln -s /var/www/html/fax/includes/faxcover.php /usr/local/bin/faxcover
ln -s /var/www/html/fax/includes/faxrcvd.php /var/spool/hylafax/bin/faxrcvd.php
ln -s /var/www/html/fax/includes/dynconf.php /var/spool/hylafax/bin/dynconf.php
ln -s /var/www/html/fax/includes/notify.php /var/spool/hylafax/bin/notify.php
pear install --alldeps Mail Net_SMTP Mail_mime MDB2_driver_mysql pear/Auth_SASL
cd …
mysql < create_user.sql
mysql avantfax < create_tables.sql

nano /etc/cron.d/avantfax

runs once an hour to update the phone book

0 * * * * /var/www/html/fax/public_html/includes/phb.php

runs once a day to remove old files

0 0 * * * /var/www/html/fax/public_html/includes/avantfaxcron.php -t 2

cp /var/www/html/fax/includes/local_config-example.php /var/www/html/fax/includes/local_config.php

#Edit local_config.php
nano /var/www/html/fax/includes/local_config.php

#Time Server

Custom Trunk

A2B local/[email protected]/n
8622466682 local/[email protected]
Google gtalk/8622466682/[email protected]

Sip Trunk Free Toll-Free Calling
TollFree voiper.ipkall.com (10 digit) proxy.ideasip.com (11 digit)

tried this command but it showed some error. any help?

easy_install sqlalchemy

-bash: easy_install: command not found

nevermind i reinstalled python.however, i cudnt understand last few lines from #Freepbx custom trunk?