2017.08.23 12:46
https://linoxide.com/ubuntu-how-to/install-asterisk-13-ubuntu-16-04-source/
Asterisk is the VoIP server with SIP and PJSIP support for Linux based operating systems and it makes great tool for learning SIP and venturing into the world of VoIP. For that purpose, we are going perform installation of Asterisk 13 on Ubuntu 16.04 Server. It will run as asterisk user and we are doing compiling from source to get latest version. During install and first run, for avoidance of problems it is best to run Asterisk as root. Later we will switch it to asterisk user for better security. Ubuntu by default has no usable root account, so lets start by making one.
After logging in to your Ubuntu Server as an user, issue following command to switch to root
sudo su
Now you are root, but you need to set password with command
passwd
Note that you still wont be able to ssh into your server as root, you would still need to ssh as user and then type su.
Next step would be to install initial dependencies for asterisk
apt-get install build-essential wget libssl-dev libncurses5-dev libnewt-dev libxml2-dev linux-headers-$(uname -r) libsqlite3-dev uuid-dev git subversion
Now when we are root and dependencies are satisfied, we can move to /usr/src/ dir and download asterisk there
cd /usr/src
wget downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
Next we unpack it.
tar zxvf asterisk-13-current.tar.gz
Now we need to cd into the newly unpacked directory, but we don't really know what the directory is called. It starts with asterisk-13 and then there is minor version which is at the time of writing this article is 13.10.0 but might change down the road because wget command we have further up, always downloads latest version of Asterisk 13 from here. So we use * (yes, asterisk) to make this guide future proof:
cd asterisk-13*
Before we actually compile the asterisk code, we need pjproject as asterisk 13 introduces the support for pjsip. So we will compile it first:
git clone git://github.com/asterisk/pjproject pjproject
cd pjproject./configure --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr CFLAGS='-O2 -DNDEBUG'
make dep
make && make install
ldconfig
ldconfig -p |grep pj
And now we commence to configuring and compiling the Asterisk code
cd ..
contrib/scripts/get_mp3_source.sh
contrib/scripts/install_prereq install
This will install mp3 tones and satisfy additional dependencies which might take some time and ask you for your country code. Following command will compile and install asterisk
./configure && make menuselect && make && make install
When that is finished, to avoid making hundred of config files yourself, after install you normally want to run this command, which will make initial config for you:
make samples
And for having the start up script installed and enabled to start asterisk on every boot, we run make config, followed by ldconfig:
make config
ldconfig
Now we can start asterisk for the first time and see if it actually works.
/etc/init.d/asterisk start
and then we can enter asterisk console with command
asterisk -rvvv
If all went well, you should to the console running asterisk as root user. That is not what we want.
So we need to do additional steps to make it run as asterisk user. First we need to stop asterisk. We can now use systemd command systemctl for starting and stopping
systemctl stop asterisk
Then we need to add group and user named asterisk.
groupadd asterisk
useradd -d /var/lib/asterisk -g asterisk asterisk
Asterisk needs to be configured to start as the user we just created, we can edit /etc/default/asterisk by hand but it is more efficient to use following two sed commands
sed -i 's/#AST_USER="asterisk"/AST_USER="asterisk"/g' /etc/default/asterisk
sed -i 's/#AST_GROUP="asterisk"/AST_GROUP="asterisk"/g' /etc/default/asterisk
To run properly, asterisk user needs to be assigned ownership to all essential asterisk directories
chown -R asterisk:asterisk /var/spool/asterisk /var/run/asterisk /etc/asterisk /var/{lib,log,spool}/asterisk /usr/lib/asterisk
The asterisk.conf also needs to be edited to uncoment lines for runuser and rungroup:
sed -i 's/;runuser = asterisk/runuser = asterisk/g' /etc/asterisk/asterisk.conf
sed -i 's/;rungroup = asterisk/rungroup = asterisk/g' /etc/asterisk/asterisk.conf
when this is done, reboot the server so Asterisk brings up automatically by systemd, and then type asterisk -rvvv to enter the asterisk console
asterisk -rvvv
Asterisk 13.10.0, Copyright (C) 1999 - 2014, Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
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 13.10.0 currently running on ubuntu (pid = 2812)
ubuntu*CLI>
If you get similar output, mainly that it is running as user asterisk and group asterisk, it means all went well. Basic setup of Asterisk 13 is done and you need to add your dial-plans and extensions to start calling from your softphones.
We have also recorded a video on how to install asterisk.
Possibilities are huge and asterisk is considerably more beginner friendly than other servers like Kamailio for example, so you wont have too much problem finding suitable configuration for your use case on the internet. You can start by reading asterisk official manuals and easy hello world example from there. Just note that they recommend Zoiper as softphone which is proprietary software and in free version doesn't support the playback and voicemail. I personally use Linphonewhich supports those features and it is fully open source and cross platform, with Linux, Windows, Mac, Android and Windows Phone versions available. You can also investigate Jitsi and Ring (former SFLphone) and see which is most comfortable for you to use. If you are connecting to your server from a Mac, you might consider Telephone, a free app from app store. With that we conclude this tutorial. If you spot an error, feel free to comment on it.