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 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.

Comments

Popular posts from this blog

PHPMixBill V5 mikrotik Billing Solutions

How to install Asterisk and A2billing on Ubuntu Server 12.04LTS

odbcinst: SQLGetPrivateProfileString failed with