How to Install Asterisk on Ubuntu 18.04

/ Category: Uncategorized / Comments: None

Spread the love

In this article, we will show you how to install Asterisk on an Ubuntu 18.04 Cloud VPS.

Asterisk is a free-to-use and open-source framework for creating real-time communications related software and is proven to be stable and reliable by thousands of users, system administrators, and developers. It controls IP PBX systems, VoIP gateways, and other custom telephone systems. Asterisk-based communications systems are being used by general communication-based businesses, call centers, carriers, and government agencies. It is also widely used to connect to telephony services like public switched telephone network (PSTN) and voice over Internet Protocol (VoIP) services.

Asterisk is licensed under GPLv2 – it is also sponsored by Digium, which offers additional licenses. The install process might take some time, so let’s get started right away.

Prerequisites

Make sure your server met the following minimum requirements:

  • 1GB of RAM or higher
  • 1 or more CPU cores
  • Fresh Ubuntu 18.04 Installation
  • Account with root access

Step 1. Install Ubuntu Updates and Dependencies

Log in to your server via SSH:

ssh [email protected]_ip

If your VPS uses a custom SSH port number, append -p port_number to the end of the above command, and replace “port_number” with your SSH port number.

Before starting with the Asterisk installation, it is a good idea to update the system packages to their latest versions.

sudo apt-get update
sudo apt-get upgrade

Install build-essential and dependencies by running the following command:

sudo apt-get install build-essential
sudo apt-get install git-core subversion wget libjansson-dev sqlite autoconf automake libxml2-dev libncurses5-dev libtool

Asterisk Versions

As of writing, the current LTS version of Asterisk is LTS version 16.x. LTS versions are fully supported for 4 years, with one additional year of maintenance for security fixes. You can find out more information about Asterisk versions here.

Step 2. Downloading Asterisk

First, we need to change our installation directory.

cd /usr/src/

We can download Asterisk source file from Asterisk’s official repository. Notice that the file name contains “current”, which means we will get the latest version starting from 16.x.

sudo wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz

Extract the files on the current directory.

sudo tar -zxvf asterisk-16-current.tar.gz

Step 3. Installing Asterisk

Change directory to the extracted file.

cd asterisk-16.*/

Asterisk source code provides a script that will install required dependencies automatically. To start, run the following command:

sudo contrib/scripts/install_prereq install

Note that it may ask some questions during dependencies installation.
Upon successful installation, you should see the following message:
#############################################
## install completed successfully
#############################################

Step 4. Configuring and Compiling Asterisk

Next step is to run the ./configure script, which will check your system for missing libraries and dependencies and prepare the Asterisk code for the build process specifically for your system:

sudo ./configure

After a successful configuration, we can now start compiling. Installation will take some time.

sudo make
sudo make install

After a successful installation, we can set up the sample configuration files using:

sudo make samples

The last step is to configure systemctl init scripts for managing Asterisk service and clear some cache:

sudo make config
sudo ldconfig

Step 5. Setting up non-root account for Asterisk

For security purposes, it is always recommended to run a service using a non-root account.
To start, supply the following command. This will create user and group “asterisk” with the home directory set to /var/lib/asterisk.

sudo groupadd asterisk
sudo adduser --system --group --home /var/lib/asterisk --no-create-home --gecos "Asterisk PBX" asterisk

Next is to add built-in Asterisk users (dialout and audio) to the “asterisk” group:

sudo usermod -a -G dialout,audio asterisk

To set up Asterisk to work with the newly created “asterisk” user, we need to modify two files:

sudo nano /etc/default/asterisk

Uncomment the following lines and add the user you just have created:
AST_USER="asterisk"
AST_GROUP="asterisk"

Then do the same in this file:

sudo nano /etc/asterisk/asterisk.conf

runuser = asterisk
rungroup = asterisk

Lastly, we will need to change the folder owner to the created user and set the correct permissions.

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

Setting up Log Rotation

You can also set up and enable the log rotation script for Asterisk:

sudo make install-logrotate

Step 6. Starting and Testing Asterisk

We should enable the Asterisk service to automatically start on server boot:

sudo systemctl enable asterisk

Now, let’s start the Asterisk service:

sudo systemctl start asterisk

To verify that Asterisk has been started, you should see “active (running)” message after running this command.

sudo systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
   Loaded: loaded (/etc/init.d/asterisk; generated)
   Active: <code>active (running)</code> since Tue 2018-12-25 20:16:30 CST; 9s ago Docs: man:systemd-sysv-generator(8) Process: 3509 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUCC Tasks: 80 (limit: 1110) CGroup: /system.slice/asterisk.service └─3522 /usr/sbin/asterisk

To see if you can access Asterik’s CLI, run this:

sudo asterisk -rvvv

You should see that you are running Asterisk using non-root account:

Running as user 'asterisk'
Running under group 'asterisk'

And that’s it. You have now successfully installed the latest version of Asterisk on your Ubuntu 18.04 Cloud VPS.


Of course, you don’t have to install Asterisk on Ubuntu 18.04 if you have Ubuntu Cloud VPS Hosting with us. You can simply ask our support team to install Asterisk on Ubuntu 18.04 for you. They are available 24/7 and will be able to help you with the installation.

PS. If you enjoyed reading this blog post on how to install Asterisk on Ubuntu 18.04, or if you found it helpful,  feel free to share it on social networks using the share shortcuts, or simply leave a comment in the comments section. Thank you.

Be the first to write a comment.

Your feedback