open voips
Asterisk PBX
VoIP Consulting | OpenSource CRM & EMR | Asterisk PBX | VoIP Billing | Calling Card| Softswitch | CallCenter

Install CentOS & PBX

Enabling the following packages:
*DNS Server
*Web Server
*Mail Server
*MySQL Database
*Development Tools

Disable Selinux:
echo "selinux=disabled" > /etc/selinux/config
reboot

Install dependencies and extra packages:

 yum install e2fsprogs-devel keyutils-libs-devel krb5-devel libogg libselinux-devel libsepol-devel libxml2-devel libtiff-devel gmp php-pear php-pear-DB php- php-mysql php-pdo kernel-devel ncurses-devel audiofile-devel libogg-devel openssl-devel mysql-devel zlib-devel perl-DateManip sendmail-cf

cd /usr/local/src
wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
tar zxvf lame-3.97.tar.gz
cd lame-3.97
./configure
make
make install


Install Asterisk and FreePBX:

 cd /usr/local/src
wget http://downloads.digium.com/pub/asterisk/asterisk-1.4.19.2.tar.gz
wget http://downloads.digium.com/pub/asterisk/asterisk-addons-1.4.3.tar.gz
wget http://downloads.digium.com/pub/zaptel/zaptel-1.4.10.1.tar.gz
wget http://downloads.digium.com/pub/libpri/libpri-1.4.4.tar.gz
wget http://mirror.freepbx.org/freepbx-2.4.0.tar.gz

tar zxvf  asterisk-1.4.19.2.tar.gz
tar zxvf asterisk-addons-1.4.3.tar.gz
tar zxvf  zaptel-1.4.10.1.tar.gz
tar zxvf libpri-1.4-current.tar.gz
tar zxvf libpri-1.4.4.tar.gz

cd /usr/local/src/zaptel-1.4.10.1 
./configure
make
make install
make config
/sbin/ztcfg

echo "/sbin/ztcfg" >> /etc/rc.d/rc.local

cd /usr/local/src/libpri-1.4.4 
./configure
make
make install
cd /usr/local/src/asterisk-1.4.19.2

Create a new user account
Use your system's preferred method of adding a new user. Examples:
  • Red Hat: adduser -c "Asterisk PBX" -d /var/lib/asterisk -u 5060 asterisk
  • Debian: addgroup --system --gid 5060 asterisk
  • Debian: adduser --system --uid 5060 --gid 5060 --home /var/lib/asterisk --no-create-home --gecos "Asterisk PBX" asterisk
  • Debian: adduser asterisk asterisk
  • Debian: adduser asterisk dialout
  • Debian: adduser asterisk audio
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/

Recompile Asterisk with a new run directory

Note: Under asterisk 1.4 and later you set this in /etc/asterisk.conf after compiling
Edit /usr/src/asterisk/Makefile and change the definition of ASTVARRUNDIR like this:
   ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run/asterisk
Edit your Asterisk config file (/etc/asterisk/asterisk.conf):
   astrundir => /var/run/asterisk

./configure
make
make install
make samples

cd /usr/local/src/asterisk-addons-1.4.3 
./configure
make
make install
make samples

vi /etc/httpd/conf/httpd.conf

Change User apache and Group apache to User asterisk and Group asterisk.

/etc/init.d/mysqld start

cd /usr/local/src/freepbx-2.3.1

mysqladmin create asterisk
mysqladmin create asteriskcdrdb
mysql asterisk < SQL/newinstall.sql
mysql asteriskcdrdb < SQL/cdr_mysql_table.sql

mysql

GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'pbx';
GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'pbx';
flush privileges;

\q

mysqladmin -u root password 'pbx'

Set file and directory permissions

The files in the /var/spool/asterisk/outgoing directory need to be owned by the asterisk user as well as writable. Writable because asterisk appends lines to indicate retry status. Owner so that it can set the utime. Covered below.

chown --recursive asterisk:asterisk /var/lib/asterisk
chown --recursive asterisk:asterisk /var/log/asterisk
chown --recursive asterisk:asterisk /var/run/asterisk
chown --recursive asterisk:asterisk /var/spool/asterisk
chown --recursive asterisk:asterisk /usr/lib/asterisk
chown --recursive asterisk:asterisk /dev/zap

   chmod --recursive u=rwX,g=rX,o= /var/lib/asterisk
   chmod --recursive u=rwX,g=rX,o= /var/log/asterisk
   chmod --recursive u=rwX,g=rX,o= /var/run/asterisk
   chmod --recursive u=rwX,g=rX,o= /var/spool/asterisk
   chmod --recursive u=rwX,g=rX,o= /usr/lib/asterisk
   chmod --recursive u=rwX,g=rX,o= /dev/zap

Also, make note that if you're running udev on your system (linux-2.6), the /dev directory
is dynamically populated with device nodes, meaning that any permissions you set on /dev/zap
will be lost on your next reboot, and you may get a nasty message such as "Asterisk ended with exit status 1"
when trying to start asterisk. Read the file /path/to/zaptel-src-1.2.x/README.udev for instructions on
how to change the user/group assigned to /dev/zap.
Asterisk needs read permission for these directories and their contents:
  • /etc/asterisk
chown --recursive root:asterisk /etc/asterisk
   chmod --recursive u=rwX,g=rX,o= /etc/asterisk

You might also have to take a look at the permissions of the web voicemail cgi files/directory.

Other files and devices may also need to be tweaked depending on your exact setup.

e.g. If you use chan_oss:
chown asterisk /dev/dsp

If running chan_capi for ISDN devices:
   chown asterisk /dev/capi20

If using the Sirrix cards :-
   chown asterisk /dev/bchdev /dev/dchdev

If using chan_alsa:
   chown --recursive asterisk /dev/snd

Suid executables

If you're using musiconhold with mpg123, you'll probably need to set the suid bit on the executable like this:

   chmod u+s /usr/local/bin/mpg123

this allows mpg123 to run as root even though Asterisk is running as a non-root user. This appears to be necessary for mpg123 to work properly under Asterisk.

However recall that mpg123 has some known security issues. Don't use it to play arbitrary data from the web.

Starting Asterisk

Method 1:
Starting asterisk is covered elsewhere. However once you've done the above changes, you can make sure asterisk runs as user asterisk and group asterisk by issuing this command in your startup scripts:

   asterisk -U asterisk

Method 2:

su asterisk -c /usr/sbin/safe_asterisk (buggy, see comment below)

cd /usr/local/src/freepbx-2.3.1
./start_asterisk start
./install_amp --username=asteriskuser --password=pbx
echo "/usr/local/sbin/amportal start" >> /etc/rc.local
chkconfig httpd on
chkconfig mysqld on

Open browser to http://ipaddress/admin
Click red bar in PBX

Configure Sendmail:

vi  /etc/mail/sendmail.mc
define(`SMART_HOST', `relay.DOMAIN.com)dnl
MASQUERADE_AS(`pbx.DOMAIN.com')dnl
FEATURE(`masquerade_envelope')dnl
Save the file.
make -C /etc/mail

Edit sip_nat.conf for proper NAT:
vi /etc/asterisk/sip_nat.conf
localnet=192.168.1.0/255.255.255.0
externhost=pbx.DOMAIN.com (Set your external hostname name here)
externrefresh=10
fromdomain=DOMAIN.com (Set your external domain name here)
nat=yes
qualify=yes
canreinvite=no

save the config file.

Add extra codecs to config:

vi /etc/asterisk/sip_custom.conf

allow=gsm
allow=h261
allow=h263
allow=h263p
videosupport=yes

vi /etc/asterisk/iax_custom.conf

allow=gsm
allow=h261
allow=h263
allow=h263p
videosupport=yes

asterisk -rx reload

Edit voicemail config:

vi /etc/amportal.conf

If the web interface on your PBX will be accessible on the internet:

AMPWEBADDRESS=pbx.DOMAIN.com (Set your external hostname name here)

If the web interface on your PBX will be accessible only on your internal network:

AMPWEBADDRESS=internal.hostname.DOMAIN.com (Set your internal hostname name here)

or if your users will NOT have access to the web interface:

vi /etc/asterisk/vm_email.inc

remove "Visit http://AMPWEBADDRESS/cgi-bin/vmail.cgi?action=login&mailbox=${VM_MAILBOX} to check your voicemail with a web browser.\n"

vi /etc/asterisk/vm_general.inc

serveremail=pbx@DOMAIN.com ; Who the e-mail notification should appear to come from
fromstring=DOMAIN PBX ; Real name of email sender

Fix MOH directory:

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

asterisk -rx reload

 Open browser to http://ipaddressopbx