Atlantic.Net Blog

How to Install Asterisk and FreePBX on Ubuntu 20.04

Asterisk is an open-source telephone solution for individuals, businesses, and governments. It runs over the Internet instead of copper phone lines and is used for voicemail, call recording, interactive voice response, and conference calling.

FreePBX is a free, open-source, web-based application used to manage the Asterisk through a browser. It offers all components required to build a phone system.  With FreePBX, you can create an extension, IVRs, set user permissions, firewall, backup and restore, and much more.

In this tutorial, we will show you how to install Asterisk and FreePBX on Ubuntu 20.04.

Prerequisites

  • A fresh Ubuntu 20.04 VPS on the Atlantic.net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server.  Create a new server, choosing Ubuntu 20.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install Required Dependencies

Before starting, you will need to install all the dependencies required to compile Asterisk on your system. You can install all of them with the following command:

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

Once all the dependencies are installed, you can proceed to compile Asterisk.

Step 3 – Install Asterisk

First, download the latest version of Asterisk from the Asterisk official website using the following command:

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

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

tar -xvzf asterisk-19-current.tar.gz

Next, change the directory to the extracted directory and install required dependencies with the following command:

cd asterisk-19.7.0
contrib/scripts/get_mp3_source.sh
contrib/scripts/install_prereq install

Next, run the following command to configure Asterisk:

./configure

Next, setup the menu options with the following command:

make menuselect

You can use Arrow key to navigate and Enter key to select.

Enable require add-ons:

Enable Core Sound Modules

Enable MOH packages

Extra Sound Packages

Once all the components are installed, build Asterisk with the following command:

make -j2

Next, install Asterisk using the following command:

make install

Next, install configs and samples using the following command:

make samples
make config
ldconfig

Step 4 – Configure Asterisk

Next, you will need to create a separate user and group for Asterisk. You can create them with the following command:

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

Next, add some required users to the Asterisk group with the following command:

usermod -aG audio,dialout asterisk

Next, set proper permissions and ownership using the following command:

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 /etc/default/asterisk file and set the asterisk user as a default user:

nano /etc/default/asterisk

Change the following lines:

AST_USER="asterisk"
AST_GROUP="asterisk"

Save and close the file, then edit the Asterisk default configuration file and define the “run as” user and group:

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 and enable it to start at system reboot with the following command:

systemctl restart asterisk
systemctl enable asterisk

Next, verify the status of the Asterisk service with the following command:

systemctl status asterisk

In some cases, you should get the following error:

radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng/radiusclient.conf: No such 
file or directory

You can resolve this error using 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

Next, start the Asterisk service again with the following command:

systemctl start asterisk

Next, connect to the Asterisk command-line interface with the following command:

asterisk -rvv

You should get the following output:

Asterisk 19.7.0, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer 
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 19.7.0 currently running on ubuntu2004 (pid = 89531)

Exit out of the CLI type:

Exit

Step 5 – Install FreePBX

FreePBX requires Apache webserver, MariaDB and PHP version 7.4 to be installed in your server. You can install all of them with the following command:

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

Once all the packages are installed, download the latest version of FreePBX using the following command:

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

Once downloaded, extract the downloaded file with the following command:

tar -xvzf freepbx-16.0-latest.tgz

Next, change the directory to the extracted directory and install the Node.js package with the following command:

cd freepbx
apt-get install nodejs npm -y

Next, set the required permissions with the following command:

./install -n

You should get the following output:

Setting specific permissions...
30690 [============================]
Finished setting permissions
Generating default configurations...
Finished generating default configurations
You have successfully installed FreePBX

Next, install pm2 package with the following command:

fwconsole ma install pm2

Next, change Apache user to asterisk and turn on AllowOverride option with the following command:

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

Next, set upload_max_filesize to php.ini file with the following command:

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

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

a2enmod rewrite
systemctl restart apache2

Step 6- Access FreePBX

Now, open your web browser and access the FreePBX web interface using the URL http://your-server-ip/admin. You will be redirected to the Admin user creation page:

Provide your Admin user details and click on the Setup System button. You should see the following page:


Click on the FreePBX Administration button. You should see the FreePBX login page:

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

Conclusion

In the above guide, you learned how to install Asterisk and FreePBX server on Ubuntu 20.04. You can now easily manage your VoIP server from the FreePBX dashboard. Install Asterisk today using your VPS hosting account with Atlantic.Net!

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year