Asterisk is a popular open-source PBX platform for developing communications applications such as conference servers and VoIP gateways. It provides a set of features including, conference calling, call queuing, call recording, voicemail, music on hold, interactive voice response, SMS messaging, and more. In this tutorial we will show you how to install Asterisk on Ubuntu 20.04.
Ubuntu repositories include an older Asterisk version. We’ll install the latest Asterisk from the source code.
Perform the following steps to install Asterisk on your Ubuntu 20.04 system:
Step 1 – Install Packages
Install the following packages that are necessary to download and build Asterisk:
You need to install following necessary packages:
sudo apt update
sudo apt install wget build-essential git autoconf subversion pkg-config libtool
Step 2 – Installing Asterisk on Ubuntu
Now we download the latest version of Asterisk from the Asterisk official website using the following command:
cd /usr/src/
sudo git clone -b 18 https://gerrit.asterisk.org/asterisk asterisk-18
Currently, at the time of writing, the latest version of Asterisk is 18.x. Next, change the directory to the extracted directory. Before continuing with the next steps, change to the Asterisk source directory:
cd asterisk-18/
Download the MP3 sources which are required to build the MP3 module and use MP3 files on Asterisk:
sudo contrib/scripts/get_mp3_source.sh
After that, install other dependencies with the following command:
sudo contrib/scripts/install_prereq install
It will show you a success message as following :
#############################################
## install completed successfully ##
#############################################
The configure
script performs several checks to make sure all of the dependencies on your system are present. Run the script by typing:
sudo ./configure
The next step is to select the modules you want to compile and install. Access menu selects, by typing:
sudo make menuselect
Select the “format_mp3” option to tell Asterisk to build the MP3 module:
After that select the “Save and Exit” button and press “Enter” and start compilation process:
sudo make -j2
The compilation process may take some time depending on your system. You can modify the -j
flag according to the number of cores in your processor.
Once completed, install and configuration Asterisk and its modules by following commands:
sudo make install
sudo make samples
sudo make basic-pbx
sudo make config
sudo ldconfig
Step 3 – Create an Asterisk User
Asterisk runs as the root user by deafult. You need to create a new system user and configure Asterisk.
Run the following command to create a new system user named asterisk
:
sudo adduser --system --group --home /var/lib/asterisk --no-create-home --gecos "Asterisk PBX" asterisk
To set default user to Asterisk, edit the /etc/default/asterisk
file:
sudo nano /etc/default/asterisk
Uncomment the following lines:
AST_USER="asterisk" AST_GROUP="asterisk"
Add the asterisk user to the dialout and audio groups:
sudo usermod -a -G dialout,audio asterisk
After that, you need to change the ownership and permissions of all asterisk files and directories so the user asterisk can access those files:
sudo chown -R asterisk: /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk
sudo chmod -R 750 /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk
Step 4 – Starting Asterisk
At this stage, all set ups are completed. Run the commands below to enable and start the Asterisk service:
sudo systemctl enable asterisk
sudo systemctl start asterisk
To verify that Asterisk is running, run the commands below:
sudo asterisk -vvvr
Step 5 – Configure Firewall
If you have an active ufw firewall, open HTTP ports and ports 5060,5061:
If you don’t have a firewall configured on your server, you can check our guide about how to set up a firewall with ufw on ubuntu.
By default, SIP uses the UDP port 5060, to open the port run:
sudo ufw allow 5060/udp
If you enabled the Real Time Protocol (RTP) then you also need to open the following port range:
sudo ufw allow 10000:20000/udp
Conclusion
Congratulations! You have successfully installed Asterisk. For additional help or useful information about, how to configure and use Asterisk check the official documentation.
Please leave a comment below if you have any problem or feedback.