How to Install Asterisk on CentOS 7
Updated on
•6 min read

Asterisk is the most popular and widely adopted open-source PBX platform that powers IP PBX systems, conference servers and VoIP gateways. It is used by individuals, small businesses, large enterprises and governments worldwide.
Asterisk features include voicemail, music on hold, conference calling, call queuing, call recording, interactive voice response and much more.
This tutorial will guide you through the steps required to install Asterisk 15 on CentOS 7.
Prerequisites
Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges .
Update your CentOS system and install the development tools that are required to compile Asterisk source code:
sudo yum update
sudo yum groupinstall core base "Development Tools"
Disable Selinux
If SELinux is set to enforcing
mode, Asterisk will not function correctly.
To disable SELinux security features, open the /etc/selinux/config
file and set SELINUX=disabled
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
Save the file and reboot your CentOS system with:
sudo shutdown -r now
Once the machine boots up, make sure that the getenforce
command returns Disabled
:
getenforce
Disabled
Download Asterisk
We are going to download Asterisk source in the /usr/src
directory which is the common location to place source files.
Change
to the /usr/src
directory by typing:
cd /usr/src/
Download the latest version of Asterisk 15 with the following wget command:
sudo wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15-current.tar.gz
Once the download is completed, extract the downloaded file using the following command:
sudo tar zxf asterisk-15-current.tar.gz
Before continuing with the next steps, make sure you change to the Asterisk source directory by typing:
cd asterisk-15.*/
Install Asterisk Dependencies
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
Next install all missing dependencies with the install_prereq
script:
sudo contrib/scripts/install_prereq install
The script will install all necessary packages and upon successful completion, it will print the following message:
#############################################
## install completed successfully
#############################################
Install Asterisk
The configure
script will perform a number of checks to make sure all of the dependencies that are required by the build and install process are present, start the script by typing:
sudo ./configure --libdir=/usr/lib64
Upon successful completion, you will see the following output:

The next step is to select the modules you want to compile and install.
Most of the modules are already enabled. Access the Menuselect system, by typing:
sudo make menuselect
We have already downloaded the MP3 source files and now we need to tell Asterisk to build the MP3 module by selecting format_mp3
:

Once you are done, press F12
to save and exit, or switch to the Save and Exit
button and press Enter
.
Start the compilation process using the make
command:
sudo make -j2
-j
flag according to the number of cores in your processor.Once the build process is completed, you will be presented with the following message:

The next step is to install Asterisk and its modules by typing:
sudo make install
Once the installation is finished the script will display the following message:

Now that the Asterisk is installed we need to install the sample configuration files.
Install either the generic configuration files with reference documentation by typing:
sudo make samples
Or install the basic PBX configuration files:
sudo make basic-pbx
The last step is to install the Asterisk init script by typing:
sudo make config
Finally run ldconfig
to update the shared libraries cache:
sudo ldconfig
Create Asterisk User
By default Asterisk runs as a root user. For security reasons we will create a new system user and configure Asterisk to run as the newly created user.
To create a new system user named asterisk
run the following command:
sudo adduser --system --user-group --home-dir /var/lib/asterisk --no-create-home asterisk
To configure Asterisk to run as asterisk
user, open the /etc/sysconfig/asterisk
file and uncomment the following two lines:
AST_USER="asterisk"
AST_GROUP="asterisk"
Add the asterisk
user to the dialout
and audio
groups:
sudo usermod -a -G dialout,audio asterisk
We also 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/lib64/asterisk /etc/asterisk
sudo chmod -R 750 /var/{lib,log,run,spool}/asterisk /usr/lib64/asterisk /etc/asterisk
Start Asterisk
Now that we are all set up, we can start the Asterisk service with the following command:
sudo systemctl start asterisk
To verify that Asterisk is running, connect to the Asterisk command line interface (CLI) by typing:
sudo asterisk -vvvr
You’ll see the default Asterisk CLI prompt:

The last step is to enable Asterisk service to start on boot with:
sudo systemctl enable asterisk
Adjust the Firewall Rules
Now that Asterisk is installed and running you need to configure your firewall to allow traffic on Asterisk specific ports.
Open your text editor of choice and create the following Firewalld service:
<?xml version="1.0" encoding="utf-8"?>
<service version="1.0">
<short>asterisk</short>
<description>Asterisk is a software implementation of a telephone private branch exchange (PBX).</description>
<port protocol="udp" port="10000-10100"/>
<port protocol="udp" port="4569"/>
<port protocol="udp" port="2727"/>
<port protocol="udp" port="5060-5061"/>
</service>
Save the file and apply the new firewall rules by typing:
sudo firewall-cmd --add-service=asterisk --permanent
sudo firewall-cmd --reload
Finally check if the new firewall rules are applied successfully with:
sudo firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: ssh dhcpv6-client asterisk
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
Feel free to adjust the firewall according to your need.
Conclusion
In this guide we have shown you how to install the latest Asterisk version from source on your CentOS system.
You should now check the Asterisk Documentation and learn more about how to configure and use Asterisk.
If you hit a problem or have feedback, leave a comment below.