How to install Asterisk PBX 13.x step by step on CentOS 7

Hi everyone, we will install Asterisk 13.0.6 in this guide. This will be a complete easy-to-follow tutorial. For the latest release of Asterisk, please see how to install Asterisk 15 PBX on CentOS 7. So let’s first define what PBX and Asterisk are?

What is PBX Asterisk is a private branch exchange first. PBX is a device that handles telephone exchanges owned by private companies rather than telephone companies. A PBX can be viewed as a dedicated telephone exchange, with one side connected to one or more telephones and the other side usually connected to one or more telephone lines. What is an asterisk?
The asterisk is the complete PBX. It implements all the major functions of most commercially available PBXs. It also implements features that would normally cost a lot in commercial installations for free: conference calls, direct access to system access, call park and call queues, to name a few.

The basic functions provided by Asterisk are:

  1. Caller ID
  2. Blacklist (block caller by caller ID)
  3. Call waiting
  4. Call forwarding
  5. telephone conference
  6. Conference Center / Bridge
  7. do not disturb
  8. Call forwarding
  9. Call park
  10. Call detail report
  11. Dial by name
  12. Interactive Voice Response (Auto Attendant)
  13. Time condition call routing
  14. Call queuing
  15. call back
  16. Music / Recording (MP3)
  17. Application integration
  18. Extended call report
  19. DISA (Direct Inward System Access)
  20. dictation
  21. Follow me
  22. Pagination / Intercom
  23. Ring group
  24. Graphical call manager
  25. Day / night control

We have updated the FreePBX 15 guide:

How to install Asterisk 15 PBX on CentOS 7

among them. So let’s get started.
You can set the host name and time zone before performing any installation. Use the following command.

sudo timedatectl  list-timezones
sudo timedatectl  set-timezone Africa/Nairobi

To set the host name, enter:

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

If your CentOS server has the wrong keyboard mapping. You can fix them.

localectl 
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us
$ localectl list-keymaps

Set up the keyboard mapping for us:

sudo localectl set-keymap us

You can set the system language to English by typing the following command as superuser on the terminal.

sudo localectl set-locale LANG=en_US.UTF-8

1. First, perform a system update

sudo yum -y update

2. Install missing dependencies

sudo yum -y install lynx mariadb-server mariadb php php-mysql 
php-mbstring tftp-server httpd ncurses-devel sendmail sendmail-cf 
sox newt-devel libxml2-devel libtiff-devel audiofile-devel gtk2-devel 
subversion kernel-devel git php-process crontabs cronie cronie-anacron 
wget vim php-xml uuid-devel sqlite-devel net-tools gnutls-devel php-pear

3. Install other missing dependencies instead of in step 2

sudo yum -y install gcc gcc-c++ php-xml php php-mysql php-pear php-mbstring mariadb-devel mariadb-server mariadb sqlite-devel lynx bison gmime-devel psmisc tftp-server httpd make ncurses-devel libtermcap-devel sendmail sendmail-cf caching-nameserver 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 php-process crontabs cronie cronie-anacron wget vim

4. Set up and configure the mariadb database and set a password.

systemctl start mariadb
systemctl enable mariadb

Now, set the password by running the following command.

mysql_secure_installation

If you haven’t set a password for mysql, press Enter. Agree to delete the test database and disable remote login.

5. Install Jansson, a C library for encoding, decoding and processing JSON data. Let’s download, unzip and compile using the following commands.

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

6. Requirements for installing traditional pears

pear install Console_Getopt

7. Download the Asterisk source file.

cd  /usr/src/asterisk-13
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
wget -O jansson.tar.gz https://github.com/akheron/jansson/archive/v2.7.tar.gz
wget http://www.pjsip.org/release/2.4/pjproject-2.4.tar.bz2

8. If you want to connect to the PSTN, compile and install DAHDI. This is optional and installs if you are connecting to the PSTN.

cd  /usr/src/asterisk-13
tar xvfz dahdi-linux-complete-current.tar.gz
tar xvfz libpri-1.4-current.tar.gz
rm -f dahdi-linux-complete-current.tar.gz libpri-1.4-current.tar.gz
cd dahdi-linux-complete-*
make all
make install
make config
cd libpri-1.4.*
make
make install

9, compile and install pjproject

cd  /usr/src/asterisk-13
tar -xjvf pjproject-2.4.tar.bz2
rm -f pjproject-2.4.tar.bz2
cd pjproject-2.4
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

10. Compile and install jansson

cd  /usr/src/asterisk-13
tar vxfz jansson.tar.gz
rm -f jansson.tar.gz
cd jansson-*
autoreconf -i
./configure --libdir=/usr/lib64
make && make install

11. Compile and install Asterisk

cd /usr/src/asterisk-13
tar xvfz asterisk-13-current.tar.gz
cd asterisk-*
./configure --libdir=/usr/lib64

12.Set the menu options by running the following command

make menuselect

On the add-ons, select chan_ooh323 and format_mp3 as shown below

How to install Asterisk PBX 13.x step by step on CentOS 7

On the Core Sound Packet, select the format of the audio data packet as shown below

How to install Asterisk PBX 13.x step by step on CentOS 7

In the music hold state, select the following modules as options, as shown in the figure below

How to install Asterisk PBX 13.x step by step on CentOS 7

On the Extra Sound Pack, the options are as follows:

How to install Asterisk PBX 13.x step by step on CentOS 7

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

cd /usr/src/asterisk-13/asterisk-*
contrib/scripts/get_mp3_source.sh

14. Install the selected module

cd /usr/src/asterisk-13/asterisk-*/
make
make install
make samples
make config

15. Create separate users and groups to run the Asterisk service

useradd -m asterisk
chown asterisk.asterisk /var/run/asterisk
chown -R asterisk.asterisk /etc/asterisk
chown -R asterisk.asterisk /var/{lib,log,spool}/asteris 
chown -R asterisk.asterisk /usr/lib64/asterisk

16. Make systemctl start with an asterisk by copying the init script into the init.d directory.

cd /usr/src/asterisk-13/asterisk-*
cp contrib/init.d/rc.redhat.asterisk  /etc/init.d/asterisk
chmod 755 /etc/init.d/asterisk

By finding the asterisk

$ which asterisk

How to install Asterisk PBX 13.x step by step on CentOS 7

Then open the file /etc/init.d/asterisk by

sudo vim /etc/init.d/asterisk

In my case, replace AST_SBIN = with the location of your asterisk binary file / sbin /. See below.

How to install Asterisk PBX 13.x step by step on CentOS 7

17. Disable SELinux

 sed -i 's/(^SELINUX=).*/SELINUX=disabled/' /etc/selinux/config
 sestatus

18. Set up the Asterisk database

[[email protected] ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 4
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> create user 'asterisk'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> create database cdrdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create database asterisk;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON asterisk.* TO [email protected] IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON cdrdb.* TO [email protected] IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges; 
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

19. Make all asterisk PBX ports accessible by adding the following rules

firewall-cmd --zone=public --add-port=5060/udp --permanent
firewall-cmd --zone=public --add-port=5060/tcp --permanent
firewall-cmd --zone=public --add-port=5061/udp --permanent
firewall-cmd --zone=public --add-port=5061/tcp --permanent
firewall-cmd --zone=public --add-port=4569/udp --permanent
firewall-cmd --zone=public --add-port=5038/tcp --permanent 
firewall-cmd --zone=public --add-port=10000-20000/udp --permanent

20. Commit Changes

[[email protected] ~]# firewall-cmd --reload
success

21. Confirm that the rule has been added.

[[email protected] ~]# firewall-cmd --zone=public --list-all 
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 5061/tcp 4569/udp 5060/tcp 10000-20000/udp 5061/udp 5060/udp 5038/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules:

Restart Asterisk server

systemctl restart asterisk

17. Check if it is running

sudo systemctl status asterisk

Further reading: How to protect Asterisk and FreePBX from VoIP fraud and brute force attacks

Sidebar