How to Setup Asterisk PBX on Ubuntu Linux

|

|

This guide provides a step-by-step tutorial on how to install Asterisk, an open-source private branch exchange platform, on Ubuntu 18.04 or 18.04 server. The process involves downloading and installing necessary packages, configuring and validating the system, creating a dedicated user for Asterisk, adjusting permissions, and starting the service. Closing instructions detail how to verify successful…

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

Asterisk is an open-source PBX platform that has been widely used across the globe to power VoIP and conferencing infrastructures for individuals, businesses, and governments. Setting up Asterisk on Ubuntu Linux can be beneficial for several reasons:

1. Cost-effective: Asterisk is an open-source platform, which means it comes at no cost, making it a cost-effective solution for businesses and institutions.

2. Flexibility: Asterisk provides a complete set of features that can be customized to meet the specific needs of a business or institution.

3. Reliability: Asterisk is known for its reliability and can be used for mission-critical applications.

4. Scalability: Asterisk can be easily scaled up or down to meet changing business needs.

5. Security: Asterisk is secure and can be configured to meet the security needs of a business or institution.

Setting up Asterisk on Ubuntu Linux can be a great option for businesses and institutions looking for a cost-effective, flexible, reliable, scalable, and secure PBX platform.

For more about Asterisk, please visit its homepage.

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

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 will manually download Asterisk packages, let’s put them in the system /usr/src directory since most of the source files are stored.

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

To get the latest version of Asterisk, visit the package repository here. Then, replace the version number in the commands below with 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 the Asterisk file is downloaded, extract it, change it into its directory, and run the installation script to 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, print out a successful message similar to the one below:

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

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

sudo ./configure

After 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 want 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 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 the 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 CPUs on your server. If your server has more than 2 CPU cores, 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 the above, you can finally install Asterisk by running the commands below:

sudo make install

After the installation, you should see a 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 sample data to help you configure 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

Creating Asterisk User

We don’t want to have an Asterisk running as the root user. So, let’s create a dedicated user that will run as an 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 an asterisk user to the dialout and audio groups:

sudo usermod -a -G dialout,audio asterisk

Next, change permissions on all Asterisk files and directories to make their users owners.

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

Starting Asterisk

At this point, all is done. Run the commands below to enable and start the 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 <markster@digium.com>
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 installations don’t have a 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.

Like this:



4 responses to “How to Setup Asterisk PBX on Ubuntu Linux”

  1. Bruno Avatar
    Bruno

    Flawless guide, worked perfectly! Thanks!!

  2. Richard Troiano Avatar
    Richard Troiano

    Other guides I tried to follow did not work, this one was flawless on a fresh Ubuntu 20.04 install. Thank you!

  3. Dave, N6BHU Avatar
    Dave, N6BHU

    I’m so glad I bookmarked this page — a few weeks later, and I’ve forgotten already how to install Asterisk! (What’s important is that I remembered the only set of instructions for installation that actually worked for me, and I didn’t have to start all over again.) I am happy to say I have successfully setup another server with Asterisk, and the fun starts once again with configurations (that luckily, I have copied to numerous places by now). Keep up the good work.

  4. pokyCoder Avatar
    pokyCoder

    This works well. One thing you did not cover was how to use a different port than the default (and very risky) 5060.

Leave a Reply to pokyCoder Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.