How to Setup Asterisk PBX on Ubuntu 20.04 | 18.04

[*]

This brief tutorial shows students and new user how to install Asterisk on Ubuntu 18.04 | 18.04 server.

For the uninitiated,  Asterisk is an open source, widely used private branch exchange (PBX) platform. Individuals, businesses and governments across the globe are using it to power their VoIP and conferencing infrastructures.

Asterisk provides a complete sets of features that include voicemail, interactive voice response, conference calling, music on hold, call queuing, call recording and many more that I can’t list here.

If you need an open source PBX platform to run your business or institution, then look no further than Asterisk. This post should come in handy and get you started and quickly.

For students and new users looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices…

When using Ubuntu, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using the system to get work done.…

Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses.

For more about Asterisk, please visit its homepage.

To get started with installing Asterisk, please follow the steps below:

Step 1: Download and Install Asterisk

To install Asterisk, you’ll have to have some basic packages installed. To install these packages, run the commands below:

sudo apt update
sudo apt install wget build-essential subversion

Since we’re going to be manually downloading Asterisk packages, let’s put in the system /usr/src directory since it’s where most source files are stored.

To do that, change into the /usr/src directory and download Asterisk.

To get the latest version of Asterisk, visit is package repository here. Then replace the version number in the commands below to the latest.

At the time of this wiring, the current version is 17.

cd /usr/src/
sudo wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-17-current.tar.gz

Once Asterisk file is downloaded, extract it, then change into its directory and run the installation script that will download and install all dependencies, including MP3 modules.

sudo tar zxf asterisk-17-current.tar.gz
cd asterisk-17.*/
sudo contrib/scripts/get_mp3_source.sh
sudo contrib/scripts/install_prereq install

After running the commands above, the script should download and install all packages. then prints out a successful message similar to the one below:

Current status: 27 (-2) upgradable.
#############################################
## install completed successfully
#############################################

Next, run the commands below to configure and perform some checks and validate that all is well.

sudo ./configure

After a successful completion, it should display similar lines as 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 :

After that, you will wand to select some modules to compile and install. You can access the menu system using the commands below:

sudo make menuselect

Because we want to use MP3 as our audio format and have already downloaded its module above, choose the format_mp3 as shown in the image below:

   ┌────────────────────────┤ Asterisk Module and Build Option Selection ├────────────────────────┐
   │                                                                                              │ 
   │   Add-ons (See README-addons.txt)        --- Extended ---                                  ↑ │ 
   │   Applications                       [ ] chan_mobile                                       ▒ │ 
   │   Bridging Modules                   [ ] chan_ooh323                                       ▒ │ 
   │   Call Detail Recording              [*] format_mp3                                        ▒ │ 
   │   Channel Event Logging              [ ] res_config_mysql                                  ▒ │ 
   │   Channel Drivers                        --- Deprecated ---                                ▒ │ 
   │   Codec Translators                  [ ] app_mysql                                         ▒ │ 
   │   Format Interpreters                [ ] cdr_mysql                                         ▮ │ 
   │   Dialplan Functions                                                                       ▒ │ 
   │   PBX Modules                                                                              ▒ │ 
   │   Resource Modules                                                                         ▒ │ 
   │   Test Modules                                                                             ▒ │ 
   │   Compiler Flags                                                                           ▒ │ 
   │   Utilities                                                                                ▒ │ 
   │   AGI Samples                                                                              ↓ │ 
   │                                                                                              │ 
   │  MP3 format [Any rate but 8000hz mono is optimal]                                            │ 
   │                                                                                              │ 
   │      Depends on: N/A                                      ┌───────────────┐   ┌──────────┐   │ 
   │         Can use: N/A                                      │  Save & Exit  │   │   Exit   │   │ 
   │  Conflicts with: N/A                                      └───────────────┘   └──────────┘   │ 
   │   Support Level: extended                                                                    │ 
   └──────────────────────────────────────────────────────────────────────────────────────────────┘ 
                                                                                                    

   toggles selection |  saves & exits |  exits without save

Once you are finished, press F12 to save and exit, or switch to the Save and Exit button and press Enter.

When you’re all done, run the commands below to start compilation process.

sudo make -j2

The compilation may take some time, depending on your system. The -j flag with the number represents the number of CPU on your server. If your server has more then 2 CPU cores, then change it to that.

Once the packages and modules are compiled, you should see a success message similar to the one below:

 +--------- Asterisk Build Complete ---------+
 + Asterisk has successfully been built, and +
 + can be installed by running:              +
 +                                           +
 +                make install               +
 +-------------------------------------------+

After compiling above, you can finally install Asterisk by running the commands below:

sudo make install

After the installation, you should see similar message as below:

 +---- 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    +
 +-------------------------------------------+
richard@ubuntu1804:/usr/src/asterisk-17.2.0$ 

Installation is complete.

You can now begin configuring your system. First you may want to add some samples data to help you with configuring your platform. To do that, run the commands below:

sudo make samples
sudo make basic-pbx

Finish the configuration by running the commands below:

sudo make config
sudo ldconfig

Step 2: Creating Asterisk User

We don’t want to have Asterisk running as the root user. So let’s create a dedicated user that will run as Asterisk.

To do that, run the commands below  to create an account and a group called asterisk.

sudo addgroup --quiet --system asterisk
sudo adduser --quiet --system --ingroup asterisk --no-create-home --disabled-password asterisk

After creating the account above, open the /etc/default/asterisk file and make the highlighted changes below:

sudo nano /etc/default/asterisk

Then make the highlighted changes below and save the file.

# Startup configuration for the Asterisk daemon

# Uncomment the following and set them to the user/groups that you
# want to run Asterisk as. NOTE: this requires substantial work to
# be sure that Asterisk's environment has permission to write the
# files required  for  its  operation, including logs, its comm
# socket, the asterisk database, etc.
AST_USER="asterisk"
AST_GROUP="asterisk"

After that, add asterisk user to the dialout and audio groups:

sudo usermod -a -G dialout,audio asterisk

Next, change permissions on all of Asterisk files and directory to make its users owner.

sudo chown -R asterisk: /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk
sudo chmod -R 750 /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk

Step 3: Starting Asterisk

At this point all is done. Run the commands below to enable and start Asterisk service.

sudo systemctl enable asterisk
sudo systemctl start asterisk

To verify that Asterisk is running, run the commands below:

sudo asterisk -vvvr

You’ll see the default Asterisk CLI prompt:

Asterisk 17.2.0, Copyright (C) 1999 - 2018, 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.
=========================================================================
Connected to Asterisk 17.2.0 currently running on ubuntu1804 (pid = 14491)
ubuntu1804*CLI> 

Most Ubuntu installation don’t have firewall enabled. If you do, you’ll want to allow the ports below.

By default, SIP uses the UDP port 5060. Open the following port.

sudo ufw allow 5060/udp

For Real Time Protocol (RTP) open the following port range:

sudo ufw allow 10000:20000/udp

That’s it!

Conclusion:

This post showed you how to install and configure Asterisk on Ubuntu 18.04 | 16.04. If you find any error above, please use the form below to report it.

You may also like the post below: