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 that manages the Asterisk through a browser. It offers all the components required to build a phone system. With FreePBX, you can create an extension, IVRs, set user permissions, firewall, backup and restore, and more.

This tutorial will show you how to install Asterisk and FreePBX on Ubuntu. This procedure is compatible with Ubuntu 20.04 and Ubuntu 22.04.

Step 1 – Install Required Dependencies

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

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

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

Step 2 – Install Asterisk

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

wget downloads.asterisk.org

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

tar -xvzf asterisk-20-current.tar.gz

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

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

Next, run the following command to configure Asterisk:

./configure

Next, set the menu options with the following command:

make menuselect

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

Enable required 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 3 – Configure Asterisk

Next, you must 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 20.4.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.
=========================================================================
Running as user 'asterisk'
Running under group 'asterisk'
Connected to Asterisk 20.4.0 currently running on ubuntu2004 (pid = 89531)

Exit out of the CLI type:

Exit

Step 4 – Install FreePBX

FreePBX requires Apache web server, MariaDB, and PHP version 7.4 to be installed on your server. First, add the PHP repository with the following command.

apt install software-properties-common
add-apt-repository ppa:ondrej/php -y

Then, install the Apache, MariaDB, PHP and other required packages with the following command.

apt install apache2 mariadb-server libapache2-mod-php7.4 php7.4 php-pear php7.4-cgi php7.4-common php7.4-curl php7.4-mbstring php7.4-gd php7.4-mysql php7.4-bcmath php7.4-zip php7.4-xml php7.4-imap php7.4-json php7.4-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-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 the pm2 package with the following command:

fwconsole ma install pm2

Next, change the Apache user to Asterisk and turn on the 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 5 – 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 on the following page:

Conclusion

The above guide taught you how to install Asterisk and FreePBX servers 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!