Atlantic.Net Blog

How to Install Asterisk and FreePBX on Ubuntu 20.04

Hitesh Jethva
by Atlantic.Net (273 posts) under VPS Hosting
0 Comments

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 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-17-current.tar.gz

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

tar zxf asterisk-17-current.tar.gz

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

cd asterisk-17.*/
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 17.8.1, Copyright (C) 1999 - 2018, Digium, Inc. 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.
=======================================================================
==
Running as user 'asterisk'
Running under group 'asterisk'
Connected to Asterisk 17.8.1 currently running on server (pid = 52652)
server*CLI>

Exit out of the CLI type:

Exit

Step 5 – Install FreePBX

FreePBX requires Apache webserver, MariaDB and PHP version 7.2 to be installed in your server. By default, Ubuntu 20.04 ships with PHP version 7.4, so you will need to install the PHP Ondrej repository to your server. You can add it with the following command:

apt-get install software-properties-common –y

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

Next, install Apache, MariaDB and PHP with 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

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-15.0-latest.tgz

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

tar -xvzf freepbx-15.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 -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, 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.2/apache2/php.ini
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/7.2/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:

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 A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS 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


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

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


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources