How to install Asterisk + FreePBX on a VPS

So you’re Fighting too much to get Asterisk and FreePBX Installed on a Dedicated VPS? Every day i install them on a 5 bucks VPS , The installation of Asterisk and FreePBX will work Just fine on any OpenVZ or virtuozzo VPS, This tutorial will teach you how to install Asterisk and FreePBX and also How to use FreePBX to setup Extensions and Incoming route so that you can use them as a call center, you may want to use them for other purposes I’m not sure , in this tutorial we will Install Asterisk and FreePBX on CentOS 5x 64BIT OS template , so Make sure you get this Installed by your VPS provider

Softwares we use in this Installation

  • CentOS 5x 64BIT
  • FreePBX 2.6
  • Asterisk 1.6

get your vps setup with centOS 5x 64BIT and get putty, if you do not know what is putty search in google as i’m not going to talk about putty in this tutorial , once you get your vps ready and you have SSH login information , login to your server as root and use the password provided by your host

Get rid of all groups and lets keep Yum Utilities
Execute the following commands

yum groupremove 'DNS Name Server'
yum groupremove 'Editors'
yum groupremove 'Legacy Network Server'
yum groupremove 'Mail Server'
yum groupremove 'Network Servers'
yum groupremove 'System Tools'
yum groupremove 'Text-based Internet'
yum groupremove 'Web Server'
yum groupremove 'Windows File Server'

Since We are Installing Asterisk on 64BIT VPS we need to edit yum.conf to prevent 32BIT packages from being installed on the system.
Let’s install yum

yum install -y nano

let’s edit yum.conf

nano /etc/yum.conf

Add the following line to the end of the file ( righ click to paste in putty ):
exclude=*.i?86

Then Ctrl+x to Exist file , type y and then Enter to save changes

Let’s update the base install

yum -y update

Now Asterisk and FreePBX Require some packages and we need to install them excute the following commands

yum groupinstall core
yum groupinstall base
yum install gcc gcc-c++ wget bison mysql-devel mysql-server php php-mysql php-pear php-pear-DB php-mbstring nano tftp-server httpd make ncurses-devel libtermcap-devel sendmail sendmail-cf caching-nameserver sox newt-devel libxml2-devel libtiff-devel php-gd audiofile-devel gtk2-devel

lets get rid of some of the unnecessary packages , Execute the following command

yum remove yum-updatesd cups cups-lpd redhat-lsb autofs pcsc-lite smartmontools cpuspeed avahi

there are some common udev problems in openvz to prevent them we need to edit rc.local

Edit rc.local

nano /etc/rc.local

Add the following line to the file

/bin/rm -rf /dev/null
/bin/rm -rf /dev/random
/bin/rm -rf /dev/tty*
/bin/rm -rf /dev/pty*
/bin/mknod /dev/null c 1 3
/bin/mknod /dev/random c 1 8
/sbin/MAKEDEV tty
/sbin/MAKEDEV pty

Then Ctrl+x to Exist file , type y and then Enter to save changes

set the server time zone
Execute the following line, change the areas names to whatever you want

ln -sf /usr/share/zoneinfo/America/Vancouver /etc/localtime

let’s get FreePBX, you can always check for the latest version if you want and update download url and name

cd /usr/src

Then

wget http://mirror.freepbx.org/freepbx-2.6.0RC2.tar.gz

Then

tar zxvf freepbx-2.6.0RC2.tar.gz

let’s get Asterisk Addons Check if this is the latest released version of Asterisk and Asterisk addons

wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-1.6.0.17.tar.gz
tar zxvf asterisk-1.6.0.17.tar.gz
wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-addons-1.6.0.3.tar.gz
tar zxvf asterisk-addons-1.6.0.3.tar.gz


Now it’s the time to Configure and compile Asterisk

cd /usr/src/asterisk-1.6.0.17
make clean
./configure; make menuselect
make
make install


Note:
Do not run Make Samples it may cause problems

now Create users and set permissions

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

then

mkdir /var/run/asterisk
chown -R asterisk /var/run/asterisk
chown -R asterisk /var/log/asterisk
chown -R asterisk /var/lib/asterisk/moh
chown -R asterisk /var/lib/php/session

Music on Hold
Asterisk default moh directory and the Freepbx default moh directory are different we need to create a symbolic link so moh files are where FreePBX expect them to be.

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

we want to install mpg123 for converting uploaded mp3′s to wav automagically

cd /usr/src
wget http://sourceforge.net/projects/mpg123/files/mpg123/1.9.1/mpg123-1.9.1.tar.bz2/download
tar -xjvf mpg123-1.9.1.tar.bz2
cd mpg123-1.9.1
make clean
./configure
make
make install
ln -s /usr/local/bin/mpg123 /usr/bin/mpg123

Change User Apache to user Asterisk

sed -i "s/User apache/User asterisk/" /etc/httpd/conf/httpd.conf

Change group Apache to Group Asterisk

sed -i "s/Group apache/Group asterisk/" /etc/httpd/conf/httpd.conf

change the default AllowOverride All to AllowOverride None to prevent .htaccess permission problems

sed -i "s/AllowOverride All/AllowOverride None/" /etc/httpd/conf/httpd.conf

Make sure Mysql is running

/etc/init.d/mysqld start

Now we will need to configure the database for freePBX.
Note that: If mysql admin password is already configured, add “-p” after the command and enter password when asked. For example, “mysqladmin -p create asterisk”.

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

FreePBX will prompt you for a database username/password when you do the install. You need to pick that now. We’ll assume that you’ve picked ‘asteriskuser’ and ’123456′ – you probably shouldn’t use these, as they are well known passwords for Freepbx. MySQL only listens to localhost by default so I would not get too paranoid about using these defaults.

mysql

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

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

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

mysql> \q
Bye

Now, after all of this, you need to pick a root ‘mysql’ password. We’ll make it ‘abcdef’ just for this example. You should use a reasonably strong password. If you need to do anything else with mysql, you’ll need to provide this password.

mysqladmin -u root password 'abcdef'

edit /usr/sbin/safe_asterisk and comment out TTY=9 to prevent errors in OpenVZ VPS

nano +5 /usr/sbin/safe_asterisk
#TTY=9

Prioritize Asterisk Process
Increase Asterisk process priority.  You can experiment with different values and see what works best.  I wouldn’t go too high as it could cause other problems.  From the command ‘top’ the PR column shows absolute priority and NI column is the relative number we add here.  Default is 0 which gives Asterisk about the same default priority as httpd and mysql.  5-10 should give top priority without crippling critical background tasks.  I believe you can go as high as 20.  This is only a prioritization recommendation setting.  The process scheduler still has ultimate authority so actual priority will vary from system to system depending on what else is installed.

nano +22 /usr/sbin/safe_asterisk
PRIORITY=10
(Ctl-x > y >ENTER)

Install FreePBX

/usr/sbin/safe_asterisk

If you didn’t run ‘make samples’ when you installed asterisk you will probably get some warning messages saying no modules will be loaded.  Just ignore and press ‘ENTER’ to get a command prompt.

cd /usr/src/freepbx-2.9.0
./install_amp

If you get any warnings or errors in the last part of the output, they’re usually not traumatic.
Leave AMPWEBADDRESS=xx.xx.xx.xx blank.  After install go into FreePBX GUI/Advanced Settings and change the xx.xx.xx.xx to blank.

Remove one of the asterisk sample files to prevent problems later when freepbx tries to create a symlink when you

install/update modules.
rm /etc/asterisk/sip_notify.conf

Default Freepbx username is: admin
Default pw is: admin

Edit /etc/asterisk/cdr_mysql.conf and add ‘loguniqueid=yes’ to the global section

nano /etc/asterisk/cdr_mysql.conf
loguniqueid=yes

set FreePBX to start on boot

echo /usr/local/sbin/amportal start >> /etc/rc.local

Enable Apache and mysql to start on boot

chkconfig httpd on
chkconfig mysqld on

Now reboot at which point you should be able to access freePBX with your web browser.  The very first thing you need to do when you enter the FreePBX Admin GUI for the first time is “Apply Configuration Changes” so all the *.conf files are created then reboot again or ‘amportal restart’ from command prompt.

SYMLINK FAIL FIX

You may get an error in the FreePBX GUI saying “symlink failed for /etc/asterisk/sip_notify.conf” or something along those lines.  If that is the case just delete or rename /etc/asterisk/sip_notify.conf.  The next time you “Apply Configuration Changes” in the FreePBX GUI after some change this file will be recreated as a symlink and the error should be gone.

MISC CONFIGURATIONS

change the “max filesize” from 2M to 20M to allow larger music on hold files

nano +582 /etc/php.ini

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

nano /etc/httpd/conf/httpd.conf

change “Listen 80″ to “Listen 8888″ or whatever port you want

/etc/rc.d/init.d/httpd restart

Instead of accessing FreePBX by http://xxx.xxx.xxx.xxx
You now access it by http://xxx.xxx.xxx.xxx:8888
setup external sip extensions if going through NATnano /etc/asterisk/sip_nat.conf

nat=yes
externip=<your fixed external IP> or
;externhost=yourdns.com
localnet=192.168.1.0/255.255.255.0
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.

logrotate setup

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
}

Sendmail configuration

Edit /etc/aliases file  and add a “root: username_to_forward_to” to forward all ‘root’ messages to your personal email address.  Put in the full email address if it is not on the asterisk system itself.
Then run

/usr/bin/newaliases

to restart the service.

If emails are not received you must set up masquerading in sendmail.  These still may be rejected if the email server requires the source of the email to also resolve to the same DNS that sendmail is masquerading as.
To enable this, add the following lines to the /etc/mail/sendmail.mc file:
MASQUERADE_AS(domain.com)dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_DOMAIN(domain.com)dnlPut a “dnl” in front of the line ”EXPOSED_USER (`root’) dnl”.  This enables host masquerading for root as well which is disabled by default.

Update the Sendmail configuration files using the m4 macro processor to generate a new sendmail.cf file by executing the following command:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
To get the Sendmail macro file, the sendmail-cf package must be installed on the system.
After creating a new /etc/mail/sendmail.cf file, restart Sendmail for the changes to take effect. To do this, use the following command:
service sendmail restart
nano /etc/asterisk/vm_general.inc
change serveremail=vm@asterisk to whom ever you want it to appear voicemail emails are coming from.

NOTE: If you are installing on a LAN or do not have a domain resolving to the IP of the VPS, Sendmail will hang for a couple minutes everytime you reboot.  To prevent this your VPS hostname should end with .local or .localhost.  So, for example, instead of naming the VPS hostname ‘powerpbx’ it should be named ‘powerpbx.local’.  The manual method is to edit your /etc/hosts file.  There should be 2 lines.
127.0.0.1 localhost.localdomain localhost
yourIPaddress yourhostname.local yourhostname yourhostname

MySQL performance tuning for low memory
This will reduce memory usage significantly without affecting performance.

nano /etc/my.cnf

[mysqld]
.
.
.
skip-innodb
skip-bdb

(Ctl-x > y > ENTER)

From command prompt:

service mysqld restart

MySQL security enhancement
This will prevent outside IP’s from connecting to the MySQL port

nano /etc/my.cnf

[mysqld]
.
.
.
bind-address = 127.0.0.1

(Ctl-x > y > ENTER)

Add Password Protection to Flash Operator Panel GUI

By default, flash operator panel GUI (/var/www/html/panel) is visible to anyone who points a browser at your server unless port 4445 is blocked by a firewall.

mkdir -p /usr/local/apache/passwd
htpasswd -c /usr/local/apache/passwd/wwwpasswd NewUserName

Apache will prompt you for a new password for the user name you’ve just indicated
New password:

Apache will prompt you to retype your new password
Re-type new password:

Apache will then confirm the new user
Adding password for user NewUserName

Now you have to add the user name you’ve just created to the “httpd.conf” file. To edit that file in “nano” type:

nano /etc/httpd/conf/httpd.conf

Now do a CTRL-W to search for “AuthUser” and you’ll find the area where all the users are listed (for example: “maint”, your AMP user).  If you don’t find any try around line 587 right after the cgi-bin “<Directory…..”  entry.

Now add the following lines:

#Password protect the Flash Operator Panel Page /var/www/html/panel
<Directory /var/www/html/panel>
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /usr/local/apache/passwd/wwwpasswd
Require user NewUserName1 NewUserName2 NewUserName3 yaddayaddayadda
</Directory>

To delete an Apache user, type in the following and then remove the user from the “httpd.conf” file.
htpasswd -D /usr/local/apache/passwd/wwwpasswd NewUserName

Then restart apache.
service httpd restart


Check out flamehosting.com for vps services :)

Post comment as twitter logo facebook logo
Sort: Newest | Oldest

your title on your page is says isntall, I think you meant "install" just incase one one else told you. -Albert

Thank you for taking the time to tell me about it!

Seems as though this tutorial has not been completed, any chance in it getting done?

Hi, I loved your tutorial, can you complete it by this week? Thanks for the above steps. It was successful.

Nice post, thanks! I'm waiting :... :)

Hello Guys, I really am sorry , I will make sure this is completed before weekend comes!

Mody, I am looking for someone to install PBX in a Flash on a VPS. Do you do this sort of consulting work or know of someone who you could recommend?

Hi, Sorry for the late response, But I have been abroad, Yes I do this sort of consulting, You can email me at mody at amaroks dot com Cheers!

anyone know how to finish the instalation? i got everything up and running up to the last part of this tutorial ... no idea how to finish though! thanks

Any chance of getting the rest of this online? I am doing a similar setup and would love to see how you did it :)

Very good tutorial many thanks! any chance you can complete it? I am stuck in the middle here. :)

Hey, I'll make sure its completed on sunday :)

Hi buddy, your blog's design is simple and clean and i like it. Your blog posts are superb. Please keep them coming. Greets!!!