Asterisk is an open source solution powering many VoIP systems in varying types of industries. The company steering the development of Asterisk is Sangoma. Asterisk can be used to build communication applications for both small, medium size and large companies. Since it can run on old hardware, the initial cost to production is minimal. The solutions build by Asterisk powers call centers, carriers and government agencies worldwide.

In today’s article we are performing an installation of Asterisk version 20 on an Ubuntu system. On the server where this install is performed, ensure SIP port 5060 UDP/TCP is not used by similar application. So let’s get started.

Features of Asterisk PBX:

  • Asterisk is written in the C Programming Language
  • It is written to run on Linux and other types of Unix
  • It powers Business Telephone Systems
  • It connects many different Telephony protocols
  • It is a toolkit for building IP PBX with many powerful features and applications , VoIP Gateways and Conferencing systems
  • Has support for VoIP Phones as well as PSTN and POTS  
  • It uses SIP , the most common VoIP protocol, among others

We assume you’re performing this setup on a fresh installation of Ubuntu Desktop or Server edition. Internet access, and user with root privileges are the main pre-reqs needed. For connection external networks using PSTN, find a service provider within your location who can give you the service.

1. Run on latest OS update

As a rule we always perform installations on an updated Ubuntu system. Run the following commands to ensure all installed packages are updated. We begin by updating package index, then OS packages.

sudo apt update && sudo apt -y upgrade

After a upgrade it’s logical to bounce the system.

[ -f /var/run/reboot-required ] && sudo reboot -f

2. Install Build Dependencies

Run the commands provided to install required dependencies.

sudo add-apt-repository universe
sudo apt -y install git curl wget libnewt-dev libssl-dev libncurses5-dev subversion libsqlite3-dev build-essential libjansson-dev libxml2-dev  uuid-dev

With the packages installed we can proceed with the installation.

3. Download Asterisk 20 tarball

Use wget command to download Asterisk on the system.

wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gz

Use tar to extract the file.

tar xvf asterisk-20-current.tar.gz

Next download the mp3 decoder library into the source tree.

cd asterisk-20*/
contrib/scripts/get_mp3_source.sh

A successful command execution will have such output;

A    addons/mp3
A    addons/mp3/MPGLIB_README
A    addons/mp3/common.c
A    addons/mp3/huffman.h
A    addons/mp3/tabinit.c
A    addons/mp3/Makefile
A    addons/mp3/README
A    addons/mp3/decode_i386.c
A    addons/mp3/dct64_i386.c
A    addons/mp3/MPGLIB_TODO
A    addons/mp3/mpg123.h
A    addons/mp3/layer3.c
A    addons/mp3/mpglib.h
A    addons/mp3/decode_ntom.c
A    addons/mp3/interface.c
Exported revision 202.

Confirm dependencies are 100% satisfied.

sudo contrib/scripts/install_prereq install

Ensure it returns success message before you proceed.

#############################################
## install completed successfully
#############################################

4. Build and Install Asterisk 20

Run the configure script to satisfy build dependencies.

./configure

Run the next command given below.

make menuselect

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

Select Addons to choose available and enable them.

install asterisk ubuntu 18.04 01 min

We can enable Core sound modules to use as seen in the screenshot.

install asterisk ubuntu 18.04 02 min

Add additional MOH packages you want to use as well.

install asterisk ubuntu 18.04 03 min

Do the same for Extra Sound Packages.

install asterisk ubuntu 18.04 04 min

When done build Asterisk from source.

$ make
.....
TROLEnc.o ooh323cDriver.o -> chan_ooh323.so
   [CC] format_mp3.c -> format_mp3.o
   [CC] mp3/common.c -> mp3/common.o
   [CC] mp3/dct64_i386.c -> mp3/dct64_i386.o
   [CC] mp3/decode_ntom.c -> mp3/decode_ntom.o
   [CC] mp3/layer3.c -> mp3/layer3.o
   [CC] mp3/tabinit.c -> mp3/tabinit.o
   [CC] mp3/interface.c -> mp3/interface.o
   [LD] format_mp3.o mp3/common.o mp3/dct64_i386.o mp3/decode_ntom.o mp3/layer3.o mp3/tabinit.o mp3/interface.o -> format_mp3.so
   [CC] res_config_mysql.c -> res_config_mysql.o
   [LD] res_config_mysql.o -> res_config_mysql.so
Building Documentation For: third-party channels pbx apps codecs formats cdr cel bridges funcs tests main res addons
 +--------- Asterisk Build Complete ---------+
 + Asterisk has successfully been built, and +
 + can be installed by running:              +
 +                                           +
 +                make install               +
 +-------------------------------------------+

Install Asterisk after building in your system.

$ sudo make install
....
make[1]: Entering directory '/home/jkmutai/asterisk-18.1.1/sounds'
make[1]: Leaving directory '/home/jkmutai/asterisk-18.1.1/sounds'
find rest-api -name "*.json" | while read x; do \
	/usr/bin/install -c -m 644 $x "/var/lib/asterisk/rest-api" ; \
done
 +---- 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    +
 +-------------------------------------------+

You can optionally install documentation:

sudo make progdocs

Install configs and samples.

sudo make samples
sudo make config
sudo ldconfig

To install sample PBX run

sudo make basic-pbx

5. Configure and Start Asterisk Service

Create Asterisk user and directories with permissions.

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

Set Asterisk default user to asterisk:

$ sudo vim /etc/default/asterisk
#Uncomment AST_USER and AST_GROUP to look like below
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 the asterisk service after making the changes.

sudo systemctl restart asterisk

Enable the service to start on system boot.

sudo systemctl enable asterisk

Check service status to see if it is running.

$ systemctl status asterisk
 asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Mon 2023-11-27 19:31:41 UTC; 35s ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 82 (limit: 4567)
     Memory: 44.6M
     CGroup: /system.slice/asterisk.service
             └─54142 /usr/sbin/asterisk -U asterisk -G asterisk

Connect to Asterisk console.

$ sudo asterisk -rvv
Asterisk 20.5.0, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation 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 20.5.0 currently running on monitoring (pid = 424549)
 asterisk*CLI> exit
Asterisk cleanly ending (0).
Executing last minute cleanups

If you have an active ufw firewall, open http ports and ports 5060,5061:

sudo ufw allow proto tcp from any to any port 5060,5061

Similar VoIP articles.

LEAVE A REPLY

Please enter your comment!
Please enter your name here