Asterisk with freePBX - hosted in SA for less than $4

juanbrunette

Member
Joined
Mar 22, 2008
Messages
10
Reaction score
0
Location
Johannesburg
Asterisk with FreePBX - all my settings and steps

I have been battling to get a cost effective and easy PBX for months now - I tried anything from a RaspberryPI, www.pbxes.org to an old workstation with CentOS 6.5. After a lot of reading and struggling I created this installation procedure and I hope it will help you in some way. This solution is based on a server in the cloud in South Africa for about R40 a month. And if you take an annual package then it becomes even cheaper. Thanks to WarwickW for all your input and help along the way.

Setup an account with www.host1plus.com and choose the South African Server in Johannesburg. You can get a trial for 14 days at http://trial.host1plus.com
I chose:
-1 Core
-512Mb Memory
-Centos 6 64Bit
-TUN/TAP
Total of about $4 a month.

Download Putty and use it to SSH to your server.

---------------------------------------------------------------------------------------
Phase 1: Initial Requirements
---------------------------------------------------------------------------------------
1) Log into your server with SSH with the details that they provide you via email.
2) Once logged in copy and paste into your SSH Console:

# Start
# Does all the YUM updates and installs needed
yum -y update
yum -y groupinstall core
yum -y groupinstall base
yum -y install gcc gcc-c++ lynx bison mysql-devel mysql-server php php-mysql php-pear php-mbstring tftp-server httpd make ncurses-devel libtermcap-devel sendmail sendmail-cf caching-nameserver sox
yum -y install newt-devel ntp libxml2-devel tunctl libtiff-devel audiofile-devel gtk2-devel subversion kernel-devel git subversion kernel-devel php-process crontabs cronie cronie-anacron wget vim php-xml yum-cron

# Installs the REPOS needed for Asterisk
cd /etc/yum.repos.d
wget http://packages.asterisk.org/centos/centos-asterisk-12.repo
wget http://packages.asterisk.org/centos/centos-asterisk-11.repo
wget http://packages.asterisk.org/centos/centos-asterisk.repo
wget http://packages.digium.com/centos/centos-digium-12.repo
wget http://packages.digium.com/centos/centos-digium-11.repo
wget http://packages.digium.com/centos/centos-digium-1.8-certified.repo
wget http://packages.digium.com/centos/centos-digium-1.8.repo
wget http://packages.digium.com/centos/centos-digium.repo

# Enables the necessary services to start after a reboot
chkconfig --level 345 mysqld on
service mysqld start
chkconfig --level 345 httpd on
service httpd start
chkconfig --level 345 iptables on
chkconfig --level 345 yum-cron on
chkconfig --level 345 ntpd on

# Sets up a weekly reboot
touch /etc/cron.weekly/reboot.cron
echo reboot >> /etc/cron.weekly/reboot.cron
chmod 777 /etc/cron.weekly/reboot.cron
ls

# Update and Install Pear
pear channel-update pear.php.net
pear install db

# Reboot the server
reboot

# Stop

---------------------------------------------------------------------------------------
Phase 2: Setup and Config
---------------------------------------------------------------------------------------
1) Log into your server with SSH with the details that they provide you via email.
2) Once logged in copy and paste into your SSH Console:

# Start
# Add the Asterisk user to your OS
adduser asterisk -M -c "Asterisk User"

# Install Asterisk
yum -y install asterisk asterisk-configs asterisk-addons --enablerepo=asterisk-12
yum -y install asterisk-sounds*

# Get the GIT for FreePBX
export VER_FREEPBX=12.0
cd /usr/src
git clone http://git.freepbx.org/scm/freepbx/framework.git freepbx
cd freepbx
git checkout release/${VER_FREEPBX}

# Set security needs
chown asterisk /var/run/asterisk
chown -R asterisk /etc/asterisk
chown -R asterisk /var/{lib,log,spool}/asterisk
chown -R asterisk /usr/lib/asterisk
chown -R asterisk /usr/lib64/asterisk
chown -R asterisk /var/www/
chown -R asterisk /var/www/*
rm -Rf /var/www/html

# Update HTTPD settings
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php.ini
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_orig
cp /var/www/html/admin/.htaccess /var/www/html/recordings/.htaccess
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/httpd/conf/httpd.conf
sed -i 's|AllowOverride None|AllowOverride All|g' /etc/httpd/conf/httpd.conf

# Setup MySQL
cd /usr/src/freepbx
export ASTERISK_DB_PW=amp109
mysqladmin -u root create asterisk
mysqladmin -u root create asteriskcdrdb
mysql -u root -e "GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY '${ASTERISK_DB_PW}';"
mysql -u root -e "GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY '${ASTERISK_DB_PW}';"
mysql -u root -e "flush privileges;"

# Does the Install - please read and answer any questions the install might ask. If not sure press enter to accept the defaults
# If there are any errors with the install part then just run these three lines again
# If you are asked to overwrite any files then choose all
cd /usr/src/freepbx
./start_asterisk start
./install_amp --installdb --username=asteriskuser --password=${ASTERISK_DB_PW}

---------------------------------------------------------------------------------------
Phase 3: Setup and Config continues
---------------------------------------------------------------------------------------
# After the install finished without errors then continue to copy and past the following lines into the SSH console
# Start
cd /usr/src/freepbx
service httpd restart
./install_amp --update-links
amportal chown
amportal a ma installall
amportal chown
amportal a reload

ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3
cd /var/lib/asterisk/moh
chmod 777 *
chown asterisk /var/run/asterisk
chown -R asterisk /etc/asterisk
chown -R asterisk /var/{lib,log,spool}/asterisk
chown -R asterisk /usr/lib/asterisk
chown -R asterisk /usr/lib64/asterisk
chown -R asterisk /var/www/
chown -R asterisk /var/www/*
chown -R asterisk /var/www/html/*
chmod 777 /etc/asterisk/indications.conf
amportal start

# Installs the commercial repos
wget -P /etc/yum.repos.d/ -N http://yum.schmoozecom.net/schmooze-commercial/schmooze-commercial.repo

yum clean all

yum -y install php-5.3-zend-guard-loader sysadmin fail2ban incron ImageMagick

service httpd restart
chkconfig --level 345 fail2ban on
amportal a ma installall
amportal a ma download sysadmin
amportal a ma install sysadmin
amportal a ma download cos
amportal a ma install cos
amportal a ma download cdr
amportal a ma install cdr
echo load = cdr_mysql.so >> /etc/asterisk/modules.conf
ls

# Configures IPTables
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -p udp --dport 5060 -j ACCEPT
iptables -A INPUT -p udp --dport 10000:20000 -j ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P INPUT DROP
iptables -L -n
iptables-save | sudo tee /etc/sysconfig/iptables
/sbin/service iptables save
service iptables restart

# Stop
--------------------------------------------------------------------------------------
Phase 4: Login to FreePBX Website
---------------------------------------------------------------------------------------
1) Login on http://yourserverIPaddress with the details that they provide you via email.
2) Create an Admin Username and Password
3) Login to the Administrator Page for FreePBX with the username and password created
4) Click on the Red Apply Config button on the top
5) Goto Settings - Advanced Settings
6) Change the Asterisk Manager Password then click on the tick and then press apply, ignore the error and do step 6.

Via SSH on the server:
7) vim /etc/amportal.conf look for (AMPMGRPASS) and make password same as in step 5
8) amportal restart

Back in the website:
9) Retry the Apply Config in FreePBX. Should apply fine.
10) Goto Admin - Asterisk Modules and check for cdr_mysql.so under Manually Loaded Modules (this is for CDR to work and Recordings to show)
11) Goto Admin - Module Admin (this is optional)
Uninstall:
Announcements
Call Flow Control
Custom Applications
Digium Addons
iSymphony
Directory
Follow Me
Digium Phones Config
Sipstation
Fax Configuration

---------------------------------------------------------------------------------------
Phase 5: Setup Trunks
---------------------------------------------------------------------------------------
1) Goto www.fnbconnect.co.za and create your FNB Number there or www.nexus.co.za and create a number there. I used FNB for my numbers.
2) Login on http://yourserverIPaddress
3) Go to Connectivity then Trunks and create a Trunk there.
4) SIP Settings for FNB:
Peer Details (Call it FNB-087322XXXX):
host=voice.fnbconnect.co.za
username=087322XXXX
authname=087322XXXX
secret=YYYYYY
type=peer
auth=md5
nat=no
disallow=all
allow=g729
context=from-trunk
insecure=port,invite
timezone=Africa/Johannesburg
trunkfreq=20
trunk=yes
qualify=yes
qualifysmoothing=yes

User Details (User Context must be the FNB Number: 087322XXXX):
secret=YYYYYY (same as secret above)
type=user
context=from-trunk

register string:
087322XXXX:YYYYYY(same as secret above)@voice.fnbconnect.co.za/087322XXXX
Same as the FNB number above. YYYYYY same as the secret above.

Create an Outbound Route - this is needed to dial out.
1) Connectivity - Outbound Routes
2) Give it a name like FNB-087322XXXX
3) Route CID 087322XXXX
4) Create 1 dial pattern that has the +27X. in match pattern
5) Create 1 dial pattern that has the X. in match pattern
6) Choose your FNB-087322XXXX trunk under trunk sequence

Follow my next phases in the next post/reply.
 
Last edited:
Previous post continued (sorry there is a limit on characters allowed in one post)

---------------------------------------------------------------------------------------
Phase 6: Create an ETH0 - needed for licensed products in Phase 7
---------------------------------------------------------------------------------------
To setup an ETH0 adaptor to license g729 and FreePBX Commercial modules add TUN/TAP to your Host1Plus package.
1) Log into your server with SSH with the details that they provide you via email.
2) Once logged in copy and paste into your SSH Console:

# Start
echo # Create the eth0 network interface: >> /etc/rc.local
echo tunctl -t eth0 >> /etc/rc.local
echo # Set the MAC address for the eth0 interface: >> /etc/rc.local
echo ip link set dev eth0 address 00:23:45:67:89:ab >> /etc/rc.local
echo # Bring up the eth0 interface: >> /etc/rc.local
echo ifconfig eth0 up >> /etc/rc.local

# Create an ETH0 config file with the following command:
touch /etc/sysconfig/network-scripts/ifcfg-eth0
echo DEVICE=eth0 >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo BOOTPROTO=static >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo IPADDR=10.10.10.10 >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo NETMASK=255.255.255.0 >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo NETWORK=10.10.10.0 >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo ONBOOT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo HWADDR=00:23:45:67:89:ab >> /etc/sysconfig/network-scripts/ifcfg-eth0

# Reboot the server
reboot

# Stop

---------------------------------------------------------------------------------------
Phase 7: Install Licensed Products
---------------------------------------------------------------------------------------
1) Login on http://yourserverIPaddress
2) Goto Admin - Module Admin
3) Install Extension Routing from Commercial Modules and then under Connectivity
4) Get free license from http://www.schmoozecom.com/
5) Create login and Deployement under Portal Login at http://www.schmoozecom.com/
4) Goto Admin - System Admin - License and register your system on http://www.schmoozecom.com/

Install G729 Codecs. For G729 you have 2 options:
Read more here: http://forums.whirlpool.net.au/archive/481223 and http://www.voip-info.org/wiki/view/Asterisk+G.729+Licensing and http://wiki.villagetelco.org/G.729

# Option 1 - Installs the G729 codec from Asterisk.lv for free but note what is said about royalties.
mkdir /Downloads
cd /Downloads
wget http://asterisk.hosting.lv/bin/codec_g723-ast120-gcc4-glibc-x86_64-barcelona.so
wget http://asterisk.hosting.lv/bin/codec_g729-ast120-gcc4-glibc-x86_64-barcelona.so
chmod 777 *
cp * /usr/lib64/asterisk/modules/
amportal restart
asterisk -rvvvvvvvvvv
core show translation
(then look to see if G729 is displayed)

# Option 2 - Installs the G729 codec from Digium - you need to license this at Digium - you need at least 2 channels for 1 call in and out.
# http://www.digium.com/en/products/asterisk/downloads and choose the Barcelona Download for G729
# http://www.digium.com/en/products/software/g729-codec to buy the license
1) Run the following commands:
mkdir /Downloads
cd /Downloads
wget http://downloads.digium.com/pub/tele...lona_64.tar.gz
chmod 777 *
cp * /usr/lib64/asterisk/modules/
wget http://downloads.digium.com/pub/register
chmod 777 *
./register
amportal restart
asterisk -rvvvvvvvvvv
core show translation
(then look for G729)

---------------------------------------------------------------------------------------
Phase 8: Setup Extensions
---------------------------------------------------------------------------------------
1) Login on http://yourserverIPaddress
2) Goto Applications - Extensions
3) Choose Generic PJSIP Extension and change/add/create only the following:
4) Enter an extension number like 101 (this is the username for your phone) and a Display Name like House
5) Outbound CID - choose the number that you got from FNB
6) Add a DID Description like FNB-Yournumber
7) Add Inbound DID like Yournumber
8) Add a Secret - this is password for your phone
9) Choose the route that the user can dial out over - This is the trunk created
10) Choose what recording options you want
11) Create a new user and give a password. Can be managed via Admin - User Management. Allow login rights as well from there.
12) Set Voicemail to enabled if you want this option
13) Set Voicemail password
14) Set Voicemail email address
15) Choose Email Attachment and Delete Voicemail

---------------------------------------------------------------------------------------
Phase 9: Odds and Ends in FreePBX
---------------------------------------------------------------------------------------
1) Login on http://yourserverIPaddress
2) Goto Settings - Advanced Settings
3) Change the Country Indication Tones to South Africa
4) Change Ringtime Default to 45 seconds
5) Change Speaking Clock Time Format to 24hr
6) Goto Admin - System Admin - Time Zone and set it to Africa - Johannesburg
7) Goto Settings - Asterisk SIP Settings - make sure g729 is ticked and moved to the top under codecs
8) Goto Settings - Asterisk SIP Settings - Chan SIP (top left) - make sure NAT is no and Static IP is chosen. Enter your server IP

---------------------------------------------------------------------------------------
Phase 10: Backups
---------------------------------------------------------------------------------------
1) Goto Admin - Backup and Restore
2) Click on New Backup
3) Give the backup a name - I called mine Weekly Backup and made the description the same
4) Enter your email address to get the alerts
5) Drag Full backup over the word Type and it will add a full backup. I also dragged over Config to add that as well.
6) Drag over Local Server over to Storage Servers. (You can click on server to add an email/FTP server etc.)
7) Run automatically weekly - will run on a Sunday at 12:00
8) I set mine to delete after 8 weeks.
9) Goto settings - Advanced Settings - Backup Module - Email Address From

General Notes:
- You don't need an FNB number for every user extension - you can make use of callgroups for Incoming calls. And all calls can use the outbound FNB number that you created.
- You can do debugging via the SSH console and "asterisk -rvvvvvvvvvv" and then type "sip set debug on"
- You can use Zoiper (mobile phone app), YATE (PC app) or Physical VOIP/SIP phones to login. I buy Fanvil C62 phones from www.scoop.co.za
 
Last edited:
Excellent guide...
www.cloudastrix.com are offering free Hosted PBX software licence too. You can select where you want to host it.
Host1plus.com will also work.

For businesses, it's better to get a hosted PBX with support as if there's a problem, the business can't afford to be spending hours browsing public forums with many suggestions trying to get the PBX up again.

All this whilst your business telecoms is down and losing revenue whilst your clients are trying to contact you.

Rackspace.com offers cheap VM servers, and they're in USA. Do you know anyone in SA offering VMs at low cost?
 
Great howto, thanks for contributing it to the community.

Over and above juanbrunette's installation I would suggest disabling the httpd server as a rule and only starting it when you need to do some configuration changes then stop it again.

ssh to server
service httpd start
<do your changes>
service httpd stop

Also possibly look at doing a GEOIP based firewall, and limit connections from only South Africa, or just your ISP's ip prefix's.
 
Last edited:
Thanks for the guide, I signed up on Host1Plus the other day and plan to use Your set-up.

I also just Signed up on Amazon AWS for another project and was wondering if anyone uses Amazon for Asterisk and what the costs are?
 
Problem with AWS for VOIP is the latency factor from SA. The closest AWS for us to use from SA would be the Ireland location and that is 160 to 180ms latency.
 
Top
Sign up to the MyBroadband newsletter
X