How to Install FreePBX on Ubuntu 20.04 (Open Source PBX Tutorial)

How to Install FreePBX on Ubuntu 20.04 (Open Source PBX Tutorial). In this tutorial we will introduce what freePBX is and move onto installation steps with Apache, MariaDB and PHP packages to be installed on your server with Asterisk. Let’s get started. 

What is FreePBX

FreePBX is a free, open source and web based user interface used for managing Asterisk “a voice over IP and telephony server” through the web browser. FreePBX is a web based open source GUI (graphical user interface) that controls Asterisk. FreePBX is  VoIP Solution and a private telephone network that allows you to connect to public landlines and mobile networks. It provides audio, video, and instant messaging communication through the TCP/IP protocol and allows you to connect it with PSTN for telephony communication.

What is Asterisk

Asterisk is a free and open source implementation of a private branch exchange (PBX). It is used for managing telephone calls between telecommunication endpoint. Asterisk provides a terminal console to manage the PBX system. Managing and configuring Asterisk via command line is very difficult for any beginner. This is where the FreePBX server comes into the picture.

Follow this post to learn how to install FreePBX on Ubuntu 20.04.

Setup FreePBX on Azure

Setup FreePBX on AWS

Setup FreePBX on Google

Install FreePBX on Ubuntu 20.04 (Open Source PBX Tutorial)

Getting Started

Before starting, it is recommended to update all packages to the latest version. Open your command line interface and run the following command to update all the packages:

				
					apt-get update -y
apt-get upgrade -y
				
			

Once all the packages are updated, you will also need to install some dependencies required for FreePBX. You can install all of them using the following command:

				
					apt-get install unzip git gnupg2 curl libnewt-dev libssl-dev libncurses5-dev subversion libsqlite3-dev build-essential libjansson-dev libxml2-dev uuid-dev subversion -y
				
			

After installing all the dependencies, you can proceed to install Asterisk.

Install Asterisk Server

FreePBX requires an Asterisk to be installed on your server. If not installed, follow the below steps to download and install Asterisk on your server.

First, go to the Asterisk official download page and download the latest version of Asterisk using the following command:

				
					wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-18-current.tar.gz
				
			

Once the download is completed, extract the downloaded file using the following command:

				
					tar -xvzf asterisk-18-current.tar.gz
				
			

Next, change the directory to the asterisk directory and run the following script to install all required dependencies:

				
					cd asterisk-18.*
contrib/scripts/get_mp3_source.sh
contrib/scripts/install_prereq install
				
			

Please configure the Asterisk using the following command:

				
					./configure
				
			

You will get the following output:

				
					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 :

				
			

Run the following command to select Asterisk modules and addons:

				
					make menuselect
				
			

Asterisk add ons

You can use the Arrow key to navigate and Enter key to select. First, enable the Addons as shown below:

Enable Core Sound Modules

In here please enable the core sound modules as shown below:

Enable MOH packages

In here enable the music on hold packages as shown below:

Enable Extra Sound Packages

Please enable the extra sound packages as shown below:

After selecting all required components, click on the Save & Exit button to close the console. Next, run the following command to build the Asterisk:

				
					make -j2
				
			

You will get the following output:

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

Next, install the Asterisk using the following command:

				
					make install
				
			

You will get the following output:

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

				
			

Next, run the following commands to install samples and config:

				
					make samples
make config
ldconfig
				
			

Configure Asterisk Server

After installing the Asterisk server, you will need to create a dedicated user and group to run Asterisk. You can create it with the following command:

				
					groupadd asterisk
useradd -r -d /var/lib/asterisk -g asterisk asterisk
				
			

Next, add the audio and dialout users to the Asterisk group:

				
					usermod -aG audio,dialout asterisk
				
			

Following that set proper permission and ownership on the Asterisk:

				
					chown -R asterisk.asterisk /etc/asterisk
chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
chown -R asterisk.asterisk /usr/lib/asterisk

				
			

Next, edit the Asterisk default configuration file:

				
					nano /etc/default/asterisk
				
			

Change the following lines:

				
					AST_USER="asterisk"
AST_GROUP="asterisk"
				
			

Save and close the file then edit the Asterisk configuration file:

				
					nano /etc/asterisk/asterisk.conf
				
			

Change the following lines:

				
					runuser = asterisk ; The user to run as.
rungroup = asterisk ; The group to run as.
				
			

Save and close the file then restart the Asterisk service:

				
					systemctl restart asterisk
				
			

Next, verify the status of the Asterisk using the following command:

				
					systemctl status asterisk
				
			

You will get the radcli error as shown below:

				
					● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Fri 2022-03-11 03:07:37 UTC; 10s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 44796 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUCCESS)
      Tasks: 81 (limit: 4686)
     Memory: 46.1M
     CGroup: /system.slice/asterisk.service
             └─44826 /usr/sbin/asterisk -U asterisk -G asterisk

Mar 11 03:07:36 freepbx systemd[1]: Starting LSB: Asterisk PBX...
Mar 11 03:07:37 freepbx asterisk[44796]:  * Starting Asterisk PBX: asterisk
Mar 11 03:07:37 freepbx asterisk[44796]:    ...done.
Mar 11 03:07:37 freepbx systemd[1]: Started LSB: Asterisk PBX.
Mar 11 03:07:37 freepbx asterisk[44826]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/radiusclient.conf: No such f>
Mar 11 03:07:37 freepbx asterisk[44826]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/radiusclient.conf: No such f>
lines 1-16/16 (END)
				
			

To fix the above error, run the following commands:

				
					sed -i 's";\[radius\]"\[radius\]"g' /etc/asterisk/cdr.conf
sed -i 's";radiuscfg => /usr/local/etc/radiusclient-ng/radiusclient.conf"radiuscfg => /etc/radcli/radiusclient.conf"g' /etc/asterisk/cdr.conf
sed -i 's";radiuscfg => /usr/local/etc/radiusclient-ng/radiusclient.conf"radiuscfg => /etc/radcli/radiusclient.conf"g' /etc/asterisk/cel.conf
				
			

Finally, restart the Asterisk service to apply the changes:

				
					systemctl restart asterisk
				
			

Now, connect to the Asterisk console with the following command:

				
					asterisk -rvv
				
			

You will get the Asterisk console as shown below:

				
					Asterisk 18.10.1, Copyright (C) 1999 - 2021, Sangoma Technologies Corporation 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 18.10.1 currently running on freepbx (pid = 44958)
freepbx*CLI> 
				
			

Run the following command to exit from the console.

				
					freepbx*CLI> exit
				
			

Install FreePBX Server

FreePBX requires the Apache server , MariaDB server, and PHP packages to be installed on your server. If not installed, follow the below steps to install them.

First, install all the dependencies using the following command:

				
					apt-get install software-properties-common -y
				
			

Next, add the PHP repository with the following command:

				
					add-apt-repository ppa:ondrej/php -y
				
			

Next, install the Apache, MariaDB, PHP and other required PHP extensions using the following command:

				
					apt-get install apache2 mariadb-server libapache2-mod-php7.2 php7.2 php-pear php7.2-cgi php7.2-common php7.2-curl php7.2-mbstring php7.2-gd php7.2-mysql php7.2-bcmath php7.2-zip php7.2-xml php7.2-imap php7.2-json php7.2-snmp -y
				
			

After installing all the packages, go to the FreePBX official download page and download the latest version of FreePBX using the following command:

				
					wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-15.0-latest.tgz
				
			

Once the download is completed, extract the downloaded file with the following command:

				
					tar -xvzf freepbx-15.0-latest.tgz
				
			

Next, navigate to the FreePBX directory and install Node.js with the following command:

				
					cd freepbx
apt-get install nodejs npm -y
				
			

Next, set required permissions with the following command:

				
					./install -n
				
			

You will get the following output:

				
					Setting Permissions...
Setting base permissions...Done in 1 seconds
Setting specific permissions...
 42913 [============================]
Finished setting permissions
Generating default configurations...
Finished generating default configurations
You have successfully installed FreePBX
				
			

Next, install the pm2 module with the following command:

				
					fwconsole ma install pm2
				
			

Next, define the Asterisk user in the Apache configuration file and turn on AllowOverride option:

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

Next, increase upload_max_filesize in php.ini:

				
					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
				
			

Finally, enable the Apache rewrite module and restart the Apache service with the following command:

				
					a2enmod rewrite
systemctl restart apache2
				
			

Access FreePBX Web UI

At this point, FreePBX is installed on Ubuntu 20.04 server. Now, open your web browser and access the FreePBX using the URL http://your-server-ip/admin. You should see the following screen:

Define your admin user, password and click on the Setup System button. You should see the following screen:

Click on the FreePBX Administration. You should see the FreePBX login screen:

Provide your admin username, password, and click on the Continue button. You should see the FreePBX dashboard on the following screen:

How to Install FreePBX on Ubuntu 20.04 Conclusion

Congratulations! you have successfully installed and configured FreePBX on Ubuntu 20.04 server. You can now add a DID (trunks), create extensions, inbound and outbound rules, call recordings, and more via the FreePBX web interface. I hope this post will help you manage your Asterisk server using FreePBX.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

5 4 votes
Article Rating
Subscribe
Notify of
2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Adolfo Arizpe

Great tutorial, thank you very much! You saved me lots of hours in trials and errors.

Just a note, not sure if it will be the case for everybody or if I missed something, but at the end of it all, I had to go back and run make menuselect again to add app_macro, run make -j2 and run make install again. Before that, my calls were failing with: No application ‘Macro’ for extension. After that, calls connect normally.

Last edited 1 year ago by Adolfo Arizpe
Thomas Carlisle

A nice write-up, but one important omission error. During the asterisk build, in the ‘make menuselect’ step, you also have to specifically check ‘app_macro’ under the ‘Applications” category. Failing to do this, freepbx isn’t going to work. Well, it will work in that it will launch and the UI will work, but calling isn’t going to work.

2
0
Would love your thoughts, please comment.x
()
x