(Last Updated On: November 26, 2018)

Asterisk is the most popular and completely open source PBX system with features of commercially available PBX systems. In this guide, we will show you how to install Asterisk 15 on CentOS 7 server.  Asterisk uses commodity Ethernet hardware and allows for the integration of physically separate installations.

Features of Asterisk PBX system

Among the good feature of Asterisk are:

  • Conference calling
  • Call Recording
  • Call Monitoring
  • Distributed Universal Number Discovery
  • Caller ID on Call Waiting
  • Direct Inward System Access
  • Call Parking
  • SMS Messaging
  • Trunking
  • Transcoding
  • Voicemail
  • Call Queues and many other features.

In our recent guide, we covered the Installation of Asterisk with FreePBX on Ubuntu 18.04 and Ubuntu 16.04 server. If you need a commercial system there is 3CX which has a guide for the installation on our blog.

UPDATE:

How to Install Asterisk 16 LTS on CentOS 7 / Fedora

How to Install Asterisk 15 on CentOS 7

Before you start executing Asterisk install commands on your CentOS 7 server, make sure all the package son the system are up to date.

sudo yum update

Set hostname type:

sudo hostnamectl set-hostname pbx-01.example.com

When done, add the epel repository

sudo yum install epel-release

Disable SELinux by running the commands below:

setenforce 0
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/sysconfig/selinux
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config

Then follow the steps below to install and configure Asterisk 15 on your CentOS 7 server

Step 1: Install Asterisk 15 PBX dependencies

The initial step when setting up Asterisk is to install all required dependencies.

sudo yum install wget vim  net-tools

You also need to install Development Tools group packages.

sudo yum groupinstall "Development Tools"

The other packages that you need to install are:

sudo yum install sqlite-devel psmisc gmime-devel ncurses-devel libtermcap-devel sox newt-devel libxml2-devel libtiff-devel audiofile-devel gtk2-devel uuid-devel libtool libuuid-devel subversion kernel-devel kernel-devel-$(uname -r) git subversion kernel-devel crontabs cronie cronie-anacron wget vim

Step 2: Download and Install Jansson

Jansson is a C library for encoding, decoding and manipulating JSON data. Download and install it on CentOS 7 server by running the commands below:

cd /usr/src
git clone https://github.com/akheron/jansson.git
cd jansson
autoreconf  -i
./configure --prefix=/usr/
make && make install

Step 3: Download and Install PJSIP

PJSIP is a free and open source multimedia communication library written in C language implementing standard based protocols such as SIP, SDP, RTP, STUN, TURN, and ICE. Clone the project from Github, then compile and install.

cd /usr/src
git clone https://github.com/pjsip/pjproject.git
cd pjproject
CFLAGS='-DPJ_HAS_IPV6=1' ./configure --prefix=/usr --enable-shared --disable-sound
--disable-resample --disable-video --disable-opencore-amr --libdir=/usr/lib64
make dep
make
make install

Step 4: Download and Install Asterisk

Now that we have all dependency packages installed, we should be ready to download and install Asterisk 15 on CentOS 7.

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15-current.tar.gz
tar xvfz asterisk-15-current.tar.gz
rm -f asterisk-15-current.tar.gz
cd asterisk-*
./configure --libdir=/usr/lib64

If all goes well, you should get output similar to below:

configure: Menuselect build configuration successfully completed

               .$$$$$$$$$$$$$$$=..      
            .$7$7..          .7$$7:.    
          .$$:.                 ,$7.7   
        .$7.     7$$$$           .$$77  
     ..$$.       $$$$$            .$$$7 
    ..7$   .?.   $$$$$   .?.       7$$$.
   $.$.   .$$$7. $$$$7 .7$$$.      .$$$.
 .777.   .$$$$$$77$$$77$$$$$7.      $$$,
 $$$~      .7$$$$$$$$$$$$$7.       .$$$.
.$$7          .7$$$$$$$7:          ?$$$.
$$$          ?7$$$$$$$$$$I        .$$$7 
$$$       .7$$$$$$$$$$$$$$$$      :$$$. 
$$$       $$$$$$7$$$$$$$$$$$$    .$$$.  
$$$        $$$   7$$$7  .$$$    .$$$.   
$$$$             $$$$7         .$$$.    
7$$$7            7$$$$        7$$$      
 $$$$$                        $$$       
  $$$$7.                       $$  (TM)     
   $$$$$$$.           .7$$$$$$  $$      
     $$$$$$$$$$$$7$$$$$$$$$.$$$$$$      
       $$$$$$$$$$$$$$$$.                

configure: Package configured for: 
configure: OS type  : linux-gnu
configure: Host CPU : x86_64
configure: build-cpu:vendor:os: x86_64 : pc : linux-gnu :
configure: host-cpu:vendor:os: x86_64 : pc : linux-gnu :

Step 5: Set Asterisk menu options

Setup menu options by running the following command:

make menuselect

Use arrow keys to navigate, and Enter key to select.

On Add-ons select chan_ooh323 and format_mp3  as shown below

On Core Sound Packages, select the formats of Audio packets like below

For Music On Hold, select the following minimal modules

On Extra Sound Packages select as shown below:

You can change other configurations you see fit. When done, save and exit

Now run the following command to download the mp3 decoder library into the source tree.

contrib/scripts/get_mp3_source.sh

To start building and installation of Asterisk with selected modules, run the commands.

make
make install
make samples
make config
ldconfig

Sample output:

---- Asterisk Installation Complete -------+
 +                                           +
 +    YOU MUST READ THE SECURITY DOCUMENT    +
 +                                           +
 + Asterisk has successfully been installed. +
 + If you would like to install the sample   +
 + configuration files (overwriting any      +
 + existing config files), run:              +
 +                                           +
 + For generic reference documentation:      +
 +    make samples                           +
 +                                           +
 + For a sample basic PBX:                   +
 +    make basic-pbx                         +
 +                                           +
 +                                           +
 +-----------------  or ---------------------+
 +                                           +
 + You can go ahead and install the asterisk +
 + program documentation now or later run:   +
 +                                           +
 +               make progdocs               +
 +                                           +
 + **Note** This requires that you have      +
 + doxygen installed on your local system    +
 +-------------------------------------------+

A systemd asterisk unit file will be created for you.

Create separate user and group to run asterisk services, and assign correct permissions:

groupadd asterisk
useradd -r -d /var/lib/asterisk -g asterisk asterisk
usermod -aG audio,dialout asterisk
chown -R asterisk.asterisk /etc/asterisk
chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
chown -R asterisk.asterisk /usr/lib64/asterisk

Set Asterisk default user to asterisk:

$ sudo vim /etc/sysconfig/asterisk
AST_USER="asterisk"
AST_GROUP="asterisk"

$ sudo vim /etc/asterisk/asterisk.conf
runuser = asterisk ; The user to run as.
rungroup = asterisk ; The group to run as.

Restart asterisk service after making the changes

sudo systemctl restart asterisk

Enable service to start on boot:

sudo systemctl enable asterisk

Test to see if you can connect to Asterisk CLI:

# asterisk -rvv
Asterisk 15.5.0, Copyright (C) 1999 - 2016, Digium, Inc. and others.
Created by Mark Spencer <[email protected]>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Running as user 'asterisk'
Running under group 'asterisk'
Connected to Asterisk 15.5.0 currently running on centos-01 (pid = 10232)
centos-01*CLI> 

You can confirm that Asterisk service is running as user asterisk. This is a recommended setting for Production.

Conclusion

You now have a running Asterisk 15 on CentOS 7 server. In our next how-to guide, we will cover the installation and Configuration of FreePBX on CentOS 7. Stay tuned and drop a comment if you encounter any issue with the setup.

Further reading: How to secure Asterisk and FreePBX from VoIP Fraud and Bruteforce attacks