(Last Updated On: August 21, 2018)

This article is designed to help you Install Asterisk 15 on Ubuntu 18.04 / Ubuntu 16.04 / Debian 9 and manage it with FreePBX 14 GUI for administering Asterisk. Asterisk is an open source complete PBX system with features of most commercially available PBXes, for example, Conference calling, Direct Inward System Access, Call Parking, and Call Queues and many other features.

For a CentOS 7 server, check How to Install Asterisk 15 PBX on CentOS 7

In this guide. we’re going to install Asterisk version 15 and FreePBX 14. If you’re in for an LTS release, consider installing Asterisk 13 or wait for Asterisk 16 which will be an LTS version. The good thing, Asterisk 13 is available on Ubuntu repositories and can be quickly installed by running sudo apt-get install asterisk

Install Asterisk 15 on Ubuntu 18.04 / Ubuntu 16.04 / Debian 9

As we start the installation, it is good practice to ensure all your system packages are latest to avoid any dependency issues:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo reboot

Step 1: Install Asterisk 15 PBX dependencies

Once the system is online, proceed to install dependency packages for Asterisk PBX.

sudo apt-get install git curl wget  libnewt-dev libssl-dev libncurses5-dev \
subversion  libsqlite3-dev build-essential libjansson-dev libxml2-dev  uuid-dev

If you get an error for subversion package on Ubuntu like below:

E: Package 'subversion' has no installation candidate

Then add universe repository and install subversion from it:

sudo add-apt-repository universe
sudo apt update
sudo apt install subversion

Step 2: Download Asterisk 15 source and Install dependencies

Since Asterisk 15 is not available from both Debian and Ubuntu upstream repositories, the installation will be done from source.

$ sudo apt policy asterisk
asterisk:
  Installed: (none)
  Candidate: 1:13.14.1~dfsg-2+deb9u3
  Version table:
     1:13.14.1~dfsg-2+deb9u3 500
...

$ sudo apt policy asterisk
asterisk:
  Installed: (none)
  Candidate: 1:13.18.3~dfsg-1ubuntu4

Download the latest release of Asterisk 15 to your local system for installation.

cd /usr/src/
curl -O http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15-current.tar.gz

Then extract the file:

tar xvf asterisk-15-current.tar.gz
cd asterisk-15*/

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

# contrib/scripts/get_mp3_source.shA addons/mp3
A addons/mp3/decode_ntom.c
A addons/mp3/interface.c
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
Exported revision 202.

Ensure all dependencies are resolved:

contrib/scripts/install_prereq install

This may take some time depending on your internet speed. Make sure you get a success message at the end:

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

Step 3: Build and Install Asterisk from source

When all dependency packages are installed, we are ready to build asterisk PBX system from source code.

You need to first run the configure script which is responsible for making sure all of the dependencies the build and install process is available. It also finds out what uses those dependencies.

./configure

A success should have an output like below:

....
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 :

Setup menu options by running the following command:

make menuselect

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

On Add-ons select chan_ooh323 and format_mp3  as shown below

On Core Sound Packages, select the formats of Audio packets like below

For Music On Hold, select the following minimal modules

On Extra Sound Packages select as shown below:

You can change other configurations you see fit. When done, save and exit then install Asterisk with selected modules:

make
make install
make samples
make config
ldconfig

A systemd asterisk unit file will be created.

Create separate user and group to run asterisk services, and assign correct permissions:

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

Set Asterisk default user to asterisk:

$ sudo vim /etc/default/asterisk
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 asterisk service after making the changes

sudo systemctl restart asterisk

Enable service to start on boot:

sudo systemctl enable asterisk

Test to see if you can connect to Asterisk CLI:

# asterisk -rvv
Asterisk 15.5.0, Copyright (C) 1999 - 2016, 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.
=========================================================================
Running as user 'asterisk'
Running under group 'asterisk'
Connected to Asterisk 15.5.0 currently running on debian-9 (pid = 25722)
debian-9*CLI> exit

Step 3: Install FreePBX 14 on Ubuntu 18.04 / Ubuntu 16.04 / Debian 9

FreePBX is a web-based open source GUI (graphical user interface) that controls and manages Asterisk (PBX). Now that we have Asterisk running happily, let’s install FreePBX.

Install MariaDB database server:

Use below links to install MariaDB on both Ubuntu 18.04 / Ubuntu 16.04 and Debian 9

Install MariaDB 10.x on Ubuntu 18.04 and CentOS 7

For Debian 9 / Debian use How to Install MariaDB 10.3 on Debian 9 / Debian 8

Install and configure Apache

Install apache2 package from apt:

sudo apt-get install apache2

Then set options below:

cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf

Install PHP

FreePBX is dependent on PHP installed, run the following commands to install php and required modules.

sudo apt-get -y install wget php php-pear php-cgi php-common php-curl \
php-mbstring php-gd php-mysql php-gettext php-bcmath php-zip php-xml \
php-imap php-json php-snmp php-fpm libapache2-mod-php

Change php maximum file upload size:

For Debian 9:

sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/7.0/cli/php.ini
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/7.0/fpm/php.ini

For Ubuntu 18.04:

sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/7.2/apache2/php.ini
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/7.2/cli/php.ini

Download and Install FreePBX

Use wget to download the latest version of FreePBX – 14 as of this writing

cd /usr/src
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-14.0-latest.tgz
tar xfz freepbx-14.0-latest.tgz
rm -f freepbx-14.0-latest.tgz
cd freepbx
./start_asterisk start
./install -n

Sample output:

Done. All modules installed.
Updating Hooks...Done
Done installing modules
Taking too long? Customize the chown command, See http://wiki.freepbx.org/display/FOP/FreePBX+Chown+Conf
Setting Permissions...
Setting base permissions...Done
Setting specific permissions...
32451 [============================]
Finished setting permissions
Generating default configurations...
Finished generating default configurations
You have successfully installed FreePBX

If you encounter an error like below:

 Unable to read /etc/asterisk/asterisk.conf or it was missing a directories section

Then edit /etc/asterisk/asterisk.conf and remove (!) at the first line. Change from

[directories](!) to [directories]

NOTE: Restore the line to [directories](!) after installing FreePBX otherwise Asterisk will fail to start.

Enable Apache Rewrite engine and restart apache2.

sudo a2enmod rewrite
sudo systemctl restart apache2

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

sudo ufw enable
sudo ufw allow 5060
sudo ufw allow 5061

That’s it!. You have a ready Asterisk 15 with FreePBX 15 on your Ubuntu / Debian server. Open up your web browser and connect to the IP address or hostname of your new FreePBX server.

You will see the Admin setup page,  set  ‘admin‘ account with a password, and configure an email address to receive update notifications.

Login to Administration panel to configure Asterisk.

I highly recommend you read How to secure Asterisk and FreePBX from VoIP Fraud and Bruteforce attacks