Asterisk is the VoIP server with SIP and PJSIP support for Linux based operating systems and it makes a great tool for learning SIP and venturing into the world of VoIP. For that purpose, we are going perform the 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 the 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 let's start by making one.
Install Asterisk from Source
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 won't 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. The 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 startup 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.
Read also :
Conclusion
Possibilities are huge and asterisk is considerably more beginner friendly than other servers like Kamailio for example, so you won't have too much problem finding the 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 Linphone which supports those features and it is a 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.
falta instalar json
install libjansson-dev
Thanks for the tutorial.
Please can you do a linphone tutorial
Thanks Nikhil. sure will try
I got an error after finished installation. When i tried to run command without reboot my pc, below the details command, :
root@ubuntu:/usr/src/asterisk-13.14.0# systemctl start asterisk
root@ubuntu:/usr/src/asterisk-13.14.0# systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
Loaded: loaded (/etc/init.d/asterisk; bad; vendor preset: enabled)
Active: active (running) since Jum 2017-03-17 18:12:50 WIB; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 10551 ExecStop=/etc/init.d/asterisk stop (code=exited, status=0/SUCCE
Process: 10619 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUC
CGroup: /system.slice/asterisk.service
└─10634 /usr/sbin/asterisk -U asterisk -G asterisk
Mar 17 18:12:50 ubuntu systemd[1]: Starting LSB: Asterisk PBX...
Mar 17 18:12:50 ubuntu asterisk[10619]: * Starting Asterisk PBX: a
Mar 17 18:12:50 ubuntu asterisk[10619]: ...done.
Mar 17 18:12:50 ubuntu systemd[1]: Started LSB: Asterisk PBX.
lines 1-13/13 (END)
after that cannot did anything, cannot type command, etc.
Please advise how to fix this problem.
All your response will be really appreciated. Thanks in advance for all your attention.
before all i hope that my bad english isn't a problem, so...
i have a problem on installation of asterisk,but when i write /etc/init.d/asterisk start the terminal show this message "Error /usr/sbin/asterisk not found"
Hi!
Thanks for the nice guide on how to install Asterisk on Ubuntu 16.04.
Greetings from Switzerland
Thanks so much, really saved me a lot of time!!
glad to hear
Thanks you a lot
How about dahdi and libpri ? There is need or not install it?
I was able to install Asterisk up to the point of the compile of the code. This is the screen contents after the compile the code string input ends.
In file included from /usr/lib/gcc/i686-linux-gnu/5/include/emmintrin.h:31:0,
from ../../webrtc/src/webrtc//modules/audio_processing/aec/aec_core_sse2.c:15:
/usr/lib/gcc/i686-linux-gnu/5/include/xmmintrin.h:929:1: error: inlining failed in call to always_inline ‘_mm_loadu_ps’: target specific option mismatch
_mm_loadu_ps (float const *__P)
^
../../webrtc/src/webrtc//modules/audio_processing/aec/aec_core_sse2.c:46:20: error: called from here
const __m128 xfBuf_re = _mm_loadu_ps(&aec->xfBuf[0][xPos + j]);
^
/usr/src/asterisk-13.33.0/pjproject/pjproject/build/rules.mak:163: recipe for target 'output/libwebrtc-i686-pc-linux-gnu/modules/audio_processing/aec/aec_core_sse2.o' failed
make[3]: *** [output/libwebrtc-i686-pc-linux-gnu/modules/audio_processing/aec/aec_core_sse2.o] Error 1
make[3]: Leaving directory '/usr/src/asterisk-13.33.0/pjproject/pjproject/third_party/build/webrtc'
Makefile:89: recipe for target 'libwebrtc-i686-pc-linux-gnu.a' failed
make[2]: *** [libwebrtc-i686-pc-linux-gnu.a] Error 2
make[2]: Leaving directory '/usr/src/asterisk-13.33.0/pjproject/pjproject/third_party/build/webrtc'
Makefile:7: recipe for target 'all' failed
make[1]: *** [all] Error 1
make[1]: Leaving directory '/usr/src/asterisk-13.33.0/pjproject/pjproject/third_party/build'
Makefile:14: recipe for target 'all' failed
make: *** [all] Error 1
root@oldoffice:/usr/src/asterisk-13.33.0/pjproject/pjproject# ldconfig
root@oldoffice:/usr/src/asterisk-13.33.0/pjproject/pjproject# ldconfig -p |grep pj
I must tell you that I am new to the Linux command line and everyday is a learning experience. Any help will be greatly appreciated. Thanks.
LKH