First install the following on a base installation of centos 5.4
yum -y update
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 ntp 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 gcc gcc-c++ kernel-devel bison openssl-devel libtermcap-devel ncurses-devel doxygen curl-devel newt-devel mlocate lynx tar wget nmap bzip2 mod_ssl crontabs vixie-cron speex speex-devel unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel mysql-connector-odbc mysql mysql-devel mysql-server php-mysql php-mbstring php-mcrypt flex screen libxml2 libxml2-devel libtiff libtiff-devel php-pear-*
Download and install Asterisk and components
Download the latest asterisk version /usr/src/ and untar the files as follows:
cd /usr/src/
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.6.2-curr...
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-addons-1.6...
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-l...
wget http://downloads.digium.com/pub/libpri/libpri-1.4-current.tar.gz
wget http://mirror.freepbx.org/freepbx-2.6.0RC2.tar.gz
wget http://sourceforge.net/projects/mpg123/files/mpg123/1.9.1/mpg123-1.9.1.t...
tar -zxf dahdi-linux-complete-current.tar.gz
tar -zxf asterisk-1.6.2-current.tar.gz
tar -zxf libpri-1.4-current.tar.gz
tar -xjvf mpg123-1.9.1.tar.bz2
tar zxvf freepbx-2.6.0RC2.tar.gz
Compile asterisk
Libpri
If you are using E1 cards you need to install LIBPRI. If you do want to use LIBPRI, make sure you compile and install it before you compile Asterisk. Replace 'VERSION' with the correct details.
cd /usr/src/asterisk/libpri-VERSION
make clean
make
make install
DAHDI
You're pretty much going to need DAHDI. If not for any hardware then for the dummy timer anyway. Note that the stock CentOS kernels come with a 1000HZ timer and so don't need recompiling (phew!). Replace 'VERSION' with the correct details.
cd /usr/src/asterisk/dahdi-linux-complete-VERSION
make all
make install
make config
Edit /etc/dahdi/modules.conf, /etc/dahdi/system.conf and /etc/asterisk/chan_dahdi.conf for your site.
Set DAHDI to start automatically and then start it.
chkconfig dahdi on
service dahdi start
Asterisk
cd /usr/src/asterisk/asterisk-VERSION
make clean
./configure
Choose which options to install (audio files, voicemail storage, codecs etc.)
make menuselect
make
make install
Install sample files in /etc/asterisk, install docs/manpages and set to start on boot.
make samples
make progdocs
make config
chkconfig asterisk on
Check Asterisk starts properly:
asterisk -vvvvvvvvvvvvvvvvvvvc
stop now
If not, you've probably not been following these instructions carefully! Assuming it does start properly, you probably want to start it in the background:
service asterisk start
Then edit the following files in /etc/asterisk:
indications.conf - Change default country
modules.conf - Uncomment the line 'preload => res_odbc.so'
modules.conf - Add 'noload => pbx_ael.so' to bottom of file
modules.conf - Add 'noload => codec_dahdi.so' to the bottom of the file
Tidy up a bit (you can cut and paste all of this to the command line)
rm /etc/asterisk/extensions.ael
cat > /etc/asterisk/extensions.conf << EOF
[general]
static=yes
writeprotect=yes
autofallthrough=yes
extenpatternmatchnew=no
clearglobalvars=yes
priorityjumping=no
userscontext=default>
[globals]
[default]
exten => _.,1,Goto(i,1)
exten => i,1,NoOp(Invalid)
exten => i,n,Congestion()
exten => i,n,Hangup()
exten => h,1,NoOp(Hanging up)
EOF
rm /etc/asterisk/extensions.lua
cat > /etc/asterisk/sip.conf << EOF
[general]
context=default
allowguest=yes
match_auth_username=yes
allowoverlap=no
allowtransfer=no
realm=pbx12.vitell.co.uk
udpbindaddr=0.0.0.0
tcpenable=no
tlsenable=no
srvlookup=yes
pedantic=no
tos_sip=cs3
tos_audio=ef
tos_video=af41
tos_text=af41
cos_sip=3
cos_audio=5
cos_video=4
cos_text=3
maxexpiry=3600
minexpiry=60
defaultexpiry=120
mwiexpiry=3600
qualifyfreq=60
qualifygap=100
qualifypeers=1
vmexten=voicemail
disallow=all
allow=alaw
mohinterpret=default
mohsuggest=default
parkinglot=plaza
language=en
relaxdtmf=yes
useragent=AsteriskPBX
sdpsession=AsteriskPBX
promiscredir=no
dtmfmode=rfc2833
videosupport=no
callevents=no
alwaysauthreject=yes
shrinkcallerid=no
allowsubscribe=yes
subscribecontext=default
notifyringing=yes
notifyhold=yes
notifycid=yes
callcounter=yes
t38pt_udptl=yes,fec,maxdatagram=400
faxdetect=no
nat=no
directmedia=no
directrtpsetup=no
EOF>
Create uses and set permissions
cd /usr/src
useradd -c "Asterisk PBX" -d /var/lib/asterisk 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
Since the Asterisk default moh directory (/moh) and the Freepbx default moh directory (/mohmp3) 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
cd /usr/src/mpg123-1.9.1
make clean
./configure
make
make install
Freepbx php script cannot find mpg123 by default so we need to create a symbolic link.
ln -s /usr/local/bin/mpg123 /usr/bin/mpg123
Change User apache and Group apache to User asterisk and Group asterisk.
sed -i "s/User apache/User asterisk/" /etc/httpd/conf/httpd.conf
sed -i "s/Group apache/Group asterisk/" /etc/httpd/conf/httpd.conf
You can choose to change the default AllowOverride All to AllowOverride None to prevent .htaccess permission problems which can be frustrating to troubleshoot.
sed -i "s/AllowOverride All/AllowOverride None/" /etc/httpd/conf/httpd.conf
Set up MySQL
Before you can do anything to MySQL, you need to make sure it's running:
/etc/init.d/mysqld start
Initializing MySQL database: [ OK ]
Starting MySQL: [ OK ]
Now, to configure the databases for freePBX:
Note: 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.6.0RC2
mysqladmin create asterisk
mysqladmin create asteriskcdrdb
mysql asterisk < SQL/newinstall.sql
mysql asteriskcdrdb < SQL/cdr_mysql_table.sql
They also need to be secured, so that not just anyone can access them. freePBX will prompt you for a database password when you do the install. You need to pick that now. We'll assume that you've picked 'asteriskuser' and 'amp109' - you probably shouldn't use these, as they are well known passwords for Asterisk@Home builds. If anyone's trying to attack your machine, they will try this.
mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8 to server version: 4.1.16
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
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'. If you need to do anything else with mysql, you'll need to provide this password.
mysqladmin -u root password 'abcdef'
FreePBX pre-install
Build the cdr_mysql module for Asterisk (Yep, more compiling!)
cd /usr/src/asterisk-addons-1.6.0.3
make clean
./configure; make menuselect
At menu press "x"
make; make install
Install FreePBX
/usr/sbin/safe_asterisk
cd /usr/src/freepbx-2.6.0RC2
./install_amp
Checking for PEAR DB..OK
Checking for PEAR Console::Getopt..OK
Checking for libasteriskperl (perl bindings for asterisk)...Checking user..OK
Checking for /etc/amportal.conf../etc/amportal.conf does not exist, copying default
Creating new /etc/amportal.conf
Enter your USERNAME to connect to the 'asterisk' database: [asteriskuser]
Enter your PASSWORD to connect to the 'asterisk' database: [amp109]
Enter the hostname of the 'asterisk' database: [localhost]
Enter a USERNAME to connect to the Asterisk Manager interface: [admin]
Enter a PASSWORD to connect to the Asterisk Manager interface:[amp111]
Enter the path to use for your AMP web root:[/var/www/html]
Enter the path to use for your FOP web root:[/var/www/html/panel]
Created /var/www/html/panel
Enter the path to your Apache cgi-bin:[/var/www/cgi-bin]
Enter the IP ADDRESS or hostname used to access the AMP web-admin:[xx.xx.xx.xx] The IP Address of your Asterisk Machine
**NOTE: Leave this IP blank if you intend to access Flash Operator Panel from the Internet Enter a PASSWORD to perform call transfers with the Flash Operator Panel: [passw0rd]
Use simple Extensions [extensions] admin or separate Devices and Users [deviceanduser]? extensions
Enter directory in which to store AMP executable scripts: [/var/lib/asterisk/bin]
Created /var/lib/asterisk/bin
Enter directory in which to store super-user scripts: [/usr/sbin]
/etc/amportal.conf writtenOK
Reading /etc/amportal.conf..OK
Checking for /etc/asterisk/asterisk.conf../etc/asterisk/asterisk.conf does not exist, copying default
OK
.
.
.
OK
Please Reload Asterisk by visiting http://XXX.XXX.XXX.XX/admin
If you get any warnings or errors in the last part of the output, they're usually not traumatic, but please use the IRC Support tool to report a bug to the developers.
The amportal script is the recommended way to stop and start asterisk:
/usr/local/sbin/amportal stop
/usr/local/sbin/amportal start
Automatic start-up
echo /usr/local/sbin/amportal start >> /etc/rc.local
FreePBX Post Install
Ensure services are starting at boot time and reboot
In order to access and use freePBX we will want both Apache (httpd) and MySQL (mysqld) to be started at boot.
chkconfig httpd on
chkconfig mysqld on
You can now access freePBX with your web browser.
Edit /etc/asterisk/cdr_mysql.conf and add 'loguniqueid=yes' to the global section
nano /etc/asterisk/cdr_mysql.conf
loguniqueid=yes
To change the password for administrator "recordings" GUI (access to extension voicemail, call monitoring, recording etc.)
nano -w /var/www/html/recordings/includes/main.conf.php
$ARI_ADMIN_PASSWORD ="password"
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
The current default settings in FreePBX after a fresh install is no username/password required to access the GUI. To enable the Admin password edit /etc/amportal.conf and change Authtype=none to Authtype=database. The default username/password is admin/admin.
nano +582 /etc/php.ini
change the “max filesize” from 2M to 20M to allow larger music on hold files
Prioritize Asterisk Process
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 this setting can go as high as 20. This is only a prioritization recommendation setting. The linux 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
Firewall/Router configuration (if you don’t have a sip proxy)
The following ports needed to be forwarded to the asterisk server for various remote access
Port 80 (Freepbx web access)
Port 4445 (Flash Operator Panel web access)
Port 4569 (IAX remote phone clients)
Port 5059-5061 (registration and proxy server access, default is 5060)
Port 10000-20000 (ports reserved for RTP voice packets for SIP phone conversations by Asterisk)
NOTE: The RTP ports 10000-xxxxx forwarded in the firewall/router need to match the setting in /etc/asterisk/rtp.conf
External SIP extensions
nano /etc/asterisk/sip_nat.conf
nat=yes
externip=
;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.
Logger.conf setup
By default, Asterisk/Freepbx installs with full (debug and verbose) logging enabled. This generates a significant amount of extra write activity to the hard drives and creates a very large "var/log/asterisk/full" log file in a short amount of time. After the initial settling in period when debug logging is no longer required it is a good idea to disable this to reduce the stress on the drives and extend their life.
nano /etc/asterisk/logger.conf
change
full => notice,warning,error,debug,verbose
to
full => notice,warning,error,verbose
you will need to restart Asterisk or type LOGGER ROTATE at the CLI to get this change to take effect (reload doesn't do it apparently).
Logrotate setup
Asterisk/FreePBX does not set up a configuration to automatically rotate the log files for some reason. Kind of suprising. I only noticed because the /var/log/asterisk/full log file got to 300MB after only a month. It would probably crash the system after awhile. 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)dnl
Put 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
Backup suggestions
When backups are created in Freepbx, they are located in /var/lib/asterisk/backup and can be copied elsewhwere
If you want to restore a previous configuration, load the backup files into the above directory. You must first create the “backup” directory or whatever name you want in freepbx backup and restore module. If Voicemail problems occur after a backup restore, try restoring just the voicemail part.
Create Acronis Workstation 9.1 (or later) recovery DVD on a PC and boot the Asterisk server on it. Follow instructions to create a hard drive image of the server onto the DVD. In the event of an emergency when the Asterisk server is corrupted beyond repair, this recovery DVD can restore the server back to the fresh install state. If it complains about writing to the same DVD disk as it booted from while making the backup, just eject the drive and slide it back in again. Enable write cache on the 3ware RAID card for faster recovery.