This article is designed to help you install FreePBX 16 on Ubuntu 22.04|20.04|18.04|16.04 and manage it with FreePBX 16 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.

We’ve provided Asterisk installation steps for reference

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

sudo apt update && sudo apt -y full-upgrade
[ -f /var/run/reboot-required ] && sudo reboot -f

1. Install Asterisk PBX dependencies

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

sudo apt 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

2. Download Asterisk source

Since Asterisk 18 LTS is not available from 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 to your local system for installation.

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

Then extract the file:

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

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

$ sudo contrib/scripts/get_mp3_source.sh
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:

sudo 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
#############################################

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

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

install asterisk ubuntu 18.04 01 min

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

install asterisk ubuntu 18.04 02 min

For Music On Hold, select the following minimal modules

install asterisk ubuntu 18.04 03 min

On Extra Sound Packages select as shown below:

install asterisk ubuntu 18.04 04 min

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

The make command output:

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               +
 +-------------------------------------------+

Successful make install output:

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    +
 +-------------------------------------------+

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

cd
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

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
Executing: /lib/systemd/systemd-sysv-install enable asterisk

Service should return status of running.

$ systemctl status asterisk.service 
● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Mon 2023-11-27 19:31:41 UTC; 12min ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 65 (limit: 9426)
     Memory: 57.2M
     CGroup: /system.slice/asterisk.service
             └─424549 /usr/sbin/asterisk

Nov 27 19:31:41 monitoring systemd[1]: Starting LSB: Asterisk PBX...
Nov 27 19:31:41 monitoring asterisk[424517]:  * Starting Asterisk PBX: asterisk
Nov 27 19:31:41 monitoring asterisk[424517]:    ...done.
Nov 27 19:31:41 monitoring systemd[1]: Started LSB: Asterisk PBX.

Test to see if you can connect to Asterisk CLI:

$ 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.
=========================================================================
Connected to Asterisk 20.5.0 currently running on monitoring (pid = 424549)

ubuntu-20-04-02*CLI> exit
Asterisk cleanly ending (0).
Executing last minute cleanups

4. Install and Configure FreePBX

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.

1) Install MariaDB database server

Install MariaDB database server using apt.

sudo apt install mariadb-server

2) Install and configure Apache

Install apache2 package from apt:

sudo apt install apache2

Then set options below:

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

Remove default index.html page

sudo rm -f /var/www/html/index.html
sudo unlink  /etc/apache2/sites-enabled/000-default.conf

3) Install PHP and extensions

Add APT repository configuration dependencies:

sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2

Add the PHP packages APT repository to your Debian server.

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list

Import repository key:

wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -

Remove any current version of PHP installed:

sudo apt remove php*

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

sudo apt install php7.4 php7.4-{mysql,cli,common,imap,ldap,xml,fpm,curl,mbstring,zip,gd,gettext,xml,json,snmp}

Install PHP Apache module:

sudo apt install libapache2-mod-php7.4

4) Change PHP maximum file upload size:

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

5) Download and Install FreePBX

Use wget to download the latest version of FreePBX 16 as of this writing:

cd ~/
wget http://mirror.freepbx.org/modules/packages/freepbx/7.4/freepbx-16.0-latest.tgz
sudo tar xfz freepbx-16.0-latest.tgz
sudo rm -f freepbx-16.0-latest.tgz
cd freepbx
sudo systemctl stop asterisk
sudo ./start_asterisk start
sudo apt install nodejs npm
sudo ./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

Install all Freepbx modules

sudo fwconsole ma disablerepo commercial
sudo fwconsole ma installall
sudo fwconsole ma delete firewall
sudo fwconsole reload
sudo fwconsole restart

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

5. Access FreePBX from browser

That’s it!. You have a ready Asterisk 18 with FreePBX 16 on your Ubuntu server. Open up your web browser and connect to the ip_address_or_hostname/admin of your new FreePBX server.

install freepbx ubuntu 18.04 set username min

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 Secure Asterisk and FreePBX from VoIP Fraud and Bruteforce attacks

13 COMMENTS

    • Que version de PHP usastes, tengo la novedad que al instalarlo en Ubuntu server 20.04, no me trae todos los modulos que trae la iso de Freepbx16.

  1. Another hint 🙂 : To allow internal calling (extension to extension) also select the macro extension @ Applications

  2. Good Day to you. Firstly, a big thank you for this article.

    I am committing the above on the latest LTS of Ubuntu (22.04) and FREEPBX 15.

    All goes well (no errors) until I do the FREEPBS install.

    Below is the dialogue returned:

    XXXX@YYYY:~/freepbx$ sudo ./install -n
    Assuming you are Database Root
    Checking if SELinux is enabled…Its not (good)!
    Reading /etc/asterisk/asterisk.conf…Done
    Checking if Asterisk is running and we can talk to it as the ‘asterisk’ user…Y es. Determined Asterisk version to be: 18.12.1
    Checking if NodeJS is installed and we can get a version from it…Yes. Determin ed NodeJS version to be: 12.22.9
    Preliminary checks done. Starting FreePBX Installation
    Checking if this is a new install…Yes (No /etc/freepbx.conf file detected)
    Error!
    PDO Driver ‘mysql’ is missing from the system

    To confirm, all went well with the ‘sudo apt install mariadb-server’

    I would be most grateful for your assistance in resolving this.

    I have started from scratch 3 times now and am getting the same result.

    TIA

  3. Assuming you are Database Root
    Checking if SELinux is enabled…Its not (good)!
    Reading /etc/asterisk/asterisk.conf…Done
    Checking if Asterisk is running and we can talk to it as the ‘asterisk’ user…Yes. Determined Asterisk version to be: 18.12.1
    Checking if NodeJS is installed and we can get a version from it…Yes. Determined NodeJS version to be: 10.24.1
    Preliminary checks done. Starting FreePBX Installation
    Checking if this is a new install…Yes (No /etc/freepbx.conf file detected)
    Database Root installation checking credentials and permissions..Error!
    Invalid Database Permissions. The error was: SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO)

  4. I followed all steps and successfully installed it. But when searches for CDR records, found nothing. No data in CDR table. Please suggest

  5. Good Morning, i am installing it and it works perfect until step “./configure -n” in freepbx installation and it returns me the error “Invalid Database Permissions. The error was: SQLSTATE[HY000] [2002] No such file or directory”
    i don´t know how to fix it.
    I have install ubunto 20.04 and the recomended version that you give from the other software

  6. Thanks, brother for the tutorial, for every install of Asterisk follow your tutorial. but I think asterisk-20 is not supported with FreePBX-16. It says FreePBX-16 is not compatible with Asterisk-20 and uses older versions of Ubuntu 20.04.

    You may update it to use older versions below 19.

  7. when I enter ./install -n this happens

    PHP Fatal error: Uncaught Error: Call to undefined function FreePBX\Install\simplexml_load_file() in /root/freepbx/install:19
    Stack trace:
    #0 {main}
    thrown in /root/freepbx/install on line 19

    I am new to this and I cannot find a work around.

    TI

  8. Hi there. I was able to install (on a hosted VM), but I am unable to access the web gui. I suspect I need to whitelist my ip. I made a rule in the firewall using port 80, but still no luck. Any help you can provide?

LEAVE A REPLY

Please enter your comment!
Please enter your name here