How to Install and Setup Asterisk 13 (PBX) on Centos 7.x

September 15, 2015 | By in LINUX HOWTO, OPEN SOURCE TOOLS
| 15 Replies More

Asterisk (PBX) is an open source communication server released under the GPL license maintained by Gigium and Asterisk community. Asterisk is used for creating communication applications that turns an ordinary computer into a communication server. So, using the Asterisk in your network environment, you can connect your employees from home to the office PBX over broadband connections and can also give them voicemail, integrated with Web and E-mail.

The benefits of using Asterisk are too much, so let’s follow this tutorial to setup your own Asterisk server whether in your home, office or in your organization and enjoy with its great features to fill communication gaps.

Asterisk Prerequisites

As we will be using CentOS 7 for Asterisk setup with minimal installed packages, so make sure that your system is up to data and you have root user privileges on the system for the installation of different required packages.

1) System Update

You can use below command for system update after successful root login.

#yum update

2) Installing Required Packages

Once your system is patched with latest updates, you have to install some packages including development tools and other packages that are necessary for its successful operation. You can easily do this by using the below command that will install its all required packages included all dependencies.

[root@centos-7 ~]# yum 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

installing prerequisites

Check the list of packages that are going to be installed on your system and press “Y” to continue, this will take about 125MB of your disk space.

After successful operation you will see the list of installed packages and updates including all its required dependencies.

3) Setup MariaDB

After installation by default we can connect to the database without using any password. So, first we will enable/start mariadb services as shown in below image, so that we can setup its root password.

mariadb service

Once the MariaDB services are fine , run the below command to setup its root password and remove anonymous user, test database and disallow remote user login.

[root@centos-7 ~]# mysql_secure_installation

4) Installing libjansson

Jansson is a C library for encoding, decoding and manipulating JSON data. Let's download, unpack and compile it using the below command.

# wget

jansson download

To extract this package use below command.

# tar -zxvf jansson-2.7.tar.gz

Then change directory and configure the package as shown.

configure jasson

5) Make Jansson

Now to compile the configured package we are required to use below 'make' and 'make install' command within the same directory to compile fully functional Jansson library.

[root@centos-7 Jansson-2.7]#make clean
[root@centos-7 Jansson-2.7]#make && make install
[root@centos-7 Jansson-2.7]#ldconfig

Installing Asterisk 13.5.0

Here we go with most important download that is Asterisk. Let's download its current latest package from their official web link Asterisk Download Page. We will be using 'wget' command to download its package, so change your current directory and run the command as shown below.

wget asterisk

Using below commands unpack its package, change directory and then run its configuration command .

[root@centos-7 ~]# tar -zxvf asterisk-13.5.0.tar.gz
[root@centos-7 ~]# cd asterisk-13.5.0
[root@centos-7 asterisk-13.5.0]# ./configure --libdir=/usr/lib64

configure asterisk

Upon successful completion of asterisk installation you will find its logo as shown below.

asterisk installation

Asterisk Modules Setup

Now in the next few steps we will configure Asterisk for its necessary modules.

1) Asterisk Main menu Selection

In order to setup your menu items, let's run the below command and then choose the appropriate options.

[root@centos-7 asterisk-13.5.0]# make menuselect

Once you run this command, a new window will be opened where you can will see that for the most part , all the necessary modules are already included . You can add something or remove, when you select a module there is a brief description of its purpose. In the Add-ons to enable mp3 support module select 'format_mp3' as shown below.

add-on module

Then move to the next Core Sound Packages and select the formats of Audio packets as shown in the image.

Sound Packages

Then select all the packages from the "Music On Hold Packages" and then form the "Extra Sound Packages choose the 4 that includes a first module containing EN and the choose the "Save and Exit" button to proceed for the next step.

2) Loading mp3 Libraries

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

[root@centos-7 asterisk-13.5.0]# contrib/scripts/

mp3 modules

3) Modules Installation

Now we will proceed with installation of selected modules using the 'make command'.

make modules

So, Asterisk has been successfully built, now run the command as shown in the image to install asterisk.

[root@centos-7 asterisk-13.5.0]# make install

In response to the above command you will be greeted with below put at the end of nstallation.

+---- Asterisk Installation Complete -------+
+ +
+ +
+ Asterisk has successfully been installed. +
+ If you would like to install the sample +
+ configuration files (overwriting any +
+ existing config files), run: +
+ +
+ make samples +
+ +
+----------------- 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 +

Here we will run the below commands to install sample configuration files as indicated above.

[root@centos-7 asterisk-13.5.0]# make samples
[root@centos-7 asterisk-13.5.0]# make config

Setup Asterisk User

You can create a separate user and give him the right to work with Asterisk in order to start its services with its own user and group. To do so let's run the below command.

[root@centos-7 asterisk-13.5.0]# useradd -m asterisk
[root@centos-7 asterisk-13.5.0]# chown asterisk.asterisk /var/run/asterisk
[root@centos-7 asterisk-13.5.0]# chown -R asterisk.asterisk /etc/asterisk
[root@centos-7 asterisk-13.5.0]# chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
[root@centos-7 asterisk-13.5.0]# chown -R asterisk.asterisk /usr/lib64/asterisk
[root@centos-7 asterisk-13.5.0]# systemctl restart asterisk
[root@centos-7 asterisk-13.5.0]# systemctl status asterisk

asterisk status

Setup Firewall Rules

Now begin to set up security. By default on CentOS 7 instead of iptables uses the FirewallD.
Using below two command you can start and enable the firewalld services.

[root@centos-7 ~]# systemctl start firewalld
[root@centos-7 ~]# systemctl enable firewalld

Now allow access to the ports that are being used in asterisk PBX by adding the following rules

[root@centos-7 ~]# firewall-cmd --zone=public --add-port=5060/udp --permanent
[root@centos-7 ~]# firewall-cmd --zone=public --add-port=5060/tcp --permanent
[root@centos-7 ~]# firewall-cmd --zone=public --add-port=5061/udp --permanent
[root@centos-7 ~]# firewall-cmd --zone=public --add-port=5061/tcp --permanent
[root@centos-7 ~]# firewall-cmd --zone=public --add-port=4569/udp --permanent
[root@centos-7 ~]# firewall-cmd --zone=public --add-port=5038/tcp --permanent
[root@centos-7 ~]# firewall-cmd --zone=public --add-port=10000-20000/udp --permanent

To load new firewall rules, use the below command.

[root@centos-7 ~]# firewall-cmd --reload

To confirm that all rules had been added , you can by using the command as shown in the image.

firewall rules

Setup Asterisk Database

Let's connect to the MySQL MariaDB and create new user and database then provide it all privileges using the following commands.

[root@centos-7 ~]# mysql -u root -p
Enter password:******
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
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 '******';
MariaDB [(none)]> create database asterisk;
MariaDB [(none)]> create database cdrdb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON asterisk.* TO asterisk@localhost IDENTIFIED BY '******';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cdrdb.* TO asterisk@localhost IDENTIFIED BY '******';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]>

Launching Asterisk

Launch Asterisk for the first time after its setup on Centos 7 using below command.

[root@centos-7 ~]# asterisk -r

launch asterisk


Asterisk 13.5.0 (PBX) has been successfully installed on CentOS 7 with its required modules. If you find any mistakes in the article or inconsistencies we would be grateful if you write to us about it in the comments.


Share This :

Free Linux Ebook to Download

Comments (15)

Trackback URL | Comments RSS Feed

  1. Kashif Siddique says:

    Thank you for for your compliments :)

  2. Tommy says:

    why do you install mariadb?

  3. Vlada Svoboda says:

    Nice, thanks for save of my time!

  4. Sense says:

    Thanks for great guide, I tried to install 13.07 version with your same procedure, but I do not find any tables under cdrdb and asterisk databases.

    Here my question is should I create tables manually anything?

    thanks in advance.

  5. Richard says:

    Awesome walkthrough!

    Just one thing I would like know to do after that. Install the gui (web-based) on the CentOS.

    Thanks again.

  6. alok says:


    I want to install and configure GUI asterisk. Everything is fine as per me. But not able to login from browser. I already set the username and password on manager.conf file but not working.
    And I am confused that asterisk needs some DB or it has internal db?


  7. Dave Howard says:

    Excellent article thanks - got me through an install of v13.8.0.

    A couple of minor points:

    Installing Asterisk
    "tar -zxvf" command is missing the tar filename

    Setup Asterisk User
    I found that I could not connect to asterisk (asterisk -r) if running as 'asterisk' user. Worked fine when running as root. I received this error "Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)". Indeed asterisk.ctl was owned by 'root'.
    I also found that "chown asterisk.asterisk /var/run/asterisk" failed as the directory is not created until asterisk starts (perhaps those two problems are related?)

    MySQL DB
    The tables are empty after starting asterisk - I assume there is some further config required to actually use the maridb with asterisk?

    This article really helped me get started and I will keep plugging away :)

  8. Abir says:

    make[1]: *** No rule to make target `../main/', needed by `asterisk'. Stop. make: *** [main] Error 2

    i am facing this issue
    please help

    • Kashif S says:

      Hello Abir,

      After running ./configure delete the following line in file makeopts.embed_rules if it exists there.


      Thank you.

  9. Jose Laura Ch says:

    Good afternoon , I want to implement asterisk but they know if there is a web application that suits the asterisk to configure the annexes to the same page , you send reports and statistics ?

    Thank you

  10. Dave says:

    Thank you very much! very helpful

  11. Miki says:

    It is not running as asterisk user

  12. Bojan says:

    [root@voip-gw asterisk-13.10.0-rc3]# systemctl restart asterisk
    Failed to restart asterisk.service: Unit asterisk.service failed to load: No such file or directory.
    i got this...
    did anyone encounter the same?

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.