Asterisk installation on Ubuntu 18.04

Asterisk is an open source framework for building communications applications. Asterisk turns an ordinary computer into a communications server. Asterisk powers IP PBX systems, VoIP gateways, conference servers and other custom solutions. It is used by small businesses, large businesses, call centers, carriers and government agencies, worldwide. Asterisk is free and open source.

Step 1

Update installed OS:

# apt update
# apt upgrade

Install additional packages to compile Asterisk:

# apt install build-essential libncurses5-dev uuid-dev libxml2-dev libsqlite3-dev libssl-dev libjansson-dev libsrtp2-dev libedit-dev
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base gir1.2-harfbuzz-0.0
  icu-devtools libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev
  libcc1-0 libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-7-dev libglib2.0-bin libglib2.0-dev libglib2.0-dev-bin libgomp1
  libgraphite2-3 libgraphite2-dev libharfbuzz-dev libharfbuzz-gobject0 libharfbuzz-icu0 libharfbuzz0b libicu-dev libicu-le-hb-dev libicu-le-hb0
  libiculx60 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libncurses5-dev libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libquadmath0
  libsqlite3-dev libssl-dev libssl-doc libstdc++-7-dev libtinfo-dev libtsan0 libubsan0 libxml2-dev linux-libc-dev make manpages-dev pkg-config
  python3-distutils python3-lib2to3 uuid-dev zlib1g-dev
Need to get 54.1 MB of archives.
After this operation, 241 MB of additional disk space will be used.

For asterisk 16 install libedit-dev package

checking for LIBEDIT... no
checking for history_init in -ledit... no
configure: error: *** Please install the 'libedit' development package.

# apt install libedit-dev

checking for LIBEDIT... yes
checking for Testing for libedit unicode support... yes

For latest versions of Jansson and/or LibSRTP library you can follow this way:

[spoiler]

Compile  Jansson library instead of installing via libjansson-dev

checkout for fresh releases here http://www.digip.org/jansson/releases/

# wget http://www.digip.org/jansson/releases/jansson-2.12.tar.gz
# tar zvxf jansson-2.12.tar.gz
# cd jansson-2.12
# ./configure
# make clean && make && make install && ldconfig

if absent, during ./configure of asterisk will cause error:

checking for JANSSON... no
checking for json_dumps in -ljansson... no
configure: *** Asterisk requires libjansson and no system copy was found.
configure: *** Please install the 'libjansson' development package or
configure: *** use './configure --with-jansson-bundled'

when fixed:

checking for JANSSON... yes

 

Compile LibSRTP library instead of installing via libsrtp2-dev
checkout for fresh releases here https://github.com/cisco/libsrtp/releases

# wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz
# tar zvxf v2.2.0.tar.gz
# cd libsrtp-2.2.0/
# ./configure
# make && make runtest && make install

if absent, during ./configure of asterisk will cause error:

checking for srtp_init in -lsrtp2... no
checking for srtp_init in -lsrtp... no
.
checking for mandatory modules:  PJPROJECT CRYPTO SRTP OPENSSL... fail
configure: ***
configure: *** The SRTP installation appears to be missing or broken.
configure: *** Either correct the installation, or run configure
configure: *** including --without-srtp.

when fixed:

checking for srtp_init in -lsrtp2... yes
checking srtp2/srtp.h usability... yes
checking srtp2/srtp.h presence... yes
checking for srtp2/srtp.h... yes
checking for the ability of -lsrtp2 to be linked in a shared object... yes
checking for srtp_shutdown in -lsrtp2... yes
checking for srtp2/srtp.h... (cached) yes
checking for srtp_get_version_string in -lsrtp2... yes
checking for srtp2/srtp.h... (cached) yes

[/spoiler]

Step 2

Asterisk
at 25-05-2019 asterisk 13.26.0 , 15.7.2, 16.3.0

Then choose target asterisk version and compile:

# wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
# wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15-current.tar.gz
# wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz
# tar zvxf asterisk-13-current.tar.gz
# cd asterisk-13.26.0
# ./configure --with-pjproject-bundled --with-crypto --with-ssl=ssl --with-srtp
# make && make install && make samples && make config

For manual configuring:

# make menuselect

At current date pjproject is embedded into asterisk. Default settings:

[pjproject]  Configuring with --with-ssl=ssl --prefix=/opt/pjproject --disable-speex-codec --disable-speex-aec --disable-bcg729 --disable-gsm-codec --disable-ilbc-codec --disable-l16-codec --disable-g722-codec --disable-g7221-codec --disable-opencore-amr --disable-silk --disable-opus --disable-video --disable-v4l2 --disable-sound --disable-ext-sound --disable-sdl --disable-libyuv --disable-ffmpeg --disable-openh264 --disable-ipp --disable-libwebrtc --without-external-pa --without-external-srtp --disable-resample --disable-g711-codec --enable-epoll

Final preparation:

# groupadd asterisk
# useradd -d /var/lib/asterisk -g asterisk asterisk
# usermod -a -G dialout,audio asterisk

# chown -R asterisk: /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk
# chmod -R 750 /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk
# 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
# sed -i 's/;runuser = asterisk/runuser = asterisk/g' /etc/asterisk/asterisk.conf
# sed -i 's/;rungroup = asterisk/rungroup = asterisk/g' /etc/asterisk/asterisk.conf

# ufw allow 5060/udp
# ufw allow 10000:20000/udp

# systemctl enable asterisk
asterisk.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable asterisk

# systemctl start asterisk

# asterisk -vvvvvvvvvvvvvvvvvvvvvvvvvvr

*for applying asterisk user permissions may be OS reboot needed.