Asterisk Freepbx on CentOS (CentOS v7, Asterisk v16 or v18, Freepbx v16)

CentOS

 

 

 

This covers the installation of Asterisk v16 or v18 and Freepbx v16 GUI, from source, on CentOS v7.   This procedure is similar to our Asterisk v16 on Freepbx v15 on CentOS procedure and can be used to upgrade servers running that software.

Tested on

CentOS v7 x64
Asterisk v16 & v18
Freepbx v16
PHP v7.4

Assumptions

Console text mode (multi-user.target)
Installation done as root user (#)

Prerequisites

Ensure a basic server install with initial dependencies to start with.

yum -y update && yum -y groupinstall core && yum -y groupinstall base && yum -y install epel-release && yum -y remove sendmail
yum -y install automake gcc gcc-c++ ncurses-devel openssl-devel libxml2-devel unixODBC-devel libcurl-devel libogg-devel libvorbis-devel speex-devel spandsp-devel freetds-devel net-snmp-devel corosynclib-devel newt-devel popt-devel libtool-ltdl-devel lua-devel sqlite-devel radiusclient-ng-devel portaudio-devel neon-devel libical-devel openldap-devel gmime-devel mysql-devel bluez-libs-devel jack-audio-connection-kit-devel gsm-devel libedit-devel libuuid-devel libsrtp-devel git subversion libxslt-devel kernel-devel audiofile-devel gtk2-devel libtiff-devel libtermcap-devel ilbc-devel python-devel bison tftp-server httpd sox tzdata mysql-connector-odbc mariadb mariadb-server fail2ban jwhois xmlstarlet ghostscript libtiff-tools patch e2fsprogs mpg123 lame gstreamer postfix gamin-python vsftpd apcupsd

PHP

Install repository

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils

Install PHP v7.4

yum-config-manager --enable remi-php74
yum -y install php php-mysqlnd php-process php-pear php-mbstring php-xml php-gd php-curl

Node.js

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum -y install nodejs

ODBC

cat >> /etc/odbc.ini << EOF
[MySQL-asteriskcdrdb]
Description = MariaDB connection to 'asteriskcdrdb' database
driver = MySQL
server = localhost
database = asteriskcdrdb
Port = 3306
Socket = /var/lib/mysql/mysql.sock
option = 3
Charset=utf8
  
EOF

Miscellaneous

yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
yum install ffmpeg

Set Timezone

## FIND YOUR TIMEZONE
tzselect
## SET TIMEZONE EXAMPLE
timedatectl set-timezone America/Vancouver
​timedatectl status

Install

DAHDI

Only required if using a physical server and installing telecom hardware.  At this time, versions newer than 2.10.2 (2.11.0 and 2.11.1) do not install correctly.

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-2.10.2+2.10.2.tar.gz
tar zxvf dahdi-linux-complete-2.10*
cd /usr/src/dahdi-linux-complete-2.10*/
make all && make install && make config
systemctl restart dahdi

If make all fails try reboot and run yum install kernel-devel

Asterisk

If upgrading an existing install with older asterisk it is best to run  rm -rf /usr/lib64/asterisk/modules first.  If installing Asterisk v18 just replace asterisk-16 with asterisk-18 in the command lines.

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz
tar zxvf asterisk-16-current.tar.gz
cd /usr/src/asterisk-16*/
make distclean

Install release specific dependencies

cd /usr/src/asterisk-16*/
./contrib/scripts/install_prereq install

Configure

cd /usr/src/asterisk-16*/
./configure --libdir=/usr/lib64 --with-jansson-bundled

To view results type nano -v config.log.

Set compile options

cd /usr/src/asterisk-16*/
make menuselect

# Go to Applications and make sure app_macro is checked.
# To add/change compile options afterwards just run make menuselect and make && make install again.

Create Asterisk User, compile, install and set preliminary ownership.

adduser asterisk -s /bin/bash -c "Asterisk User"
make && make install && chown -R asterisk. /var/lib/asterisk

Freepbx

systemctl restart mariadb
cd /usr/src
git clone -b release/16.0 --single-branch https://github.com/freepbx/framework.git freepbx
touch /etc/asterisk/modules.conf
cd /usr/src/freepbx
./start_asterisk start

./install -n

Module install

fwconsole ma downloadinstall framework core voicemail sipsettings infoservices \
featurecodeadmin logfiles callrecording cdr dashboard music soundlang recordings conferences pm2
fwconsole chown
fwconsole reload

Additional modules can be installed via GUI > Admin > Module Admin.

Optionally, install all modules (not recommended).  You may need to run the following commands twice.

fwconsole ma installall
fwconsole chown
fwconsole reload

Configure Freepbx to start on boot

cat >> /etc/systemd/system/freepbx.service << EOF
[Unit]
Description=Freepbx
After=mariadb.service
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start -q
ExecStop=/usr/sbin/fwconsole stop -q
 
[Install]
WantedBy=multi-user.target

EOF
systemctl enable freepbx

Post-install tasks

Lock down the database server.

mysql_secure_installation

Answer Y to everything.

Change apache web server settings.

sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php.ini
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/httpd/conf/httpd.conf
sed -i ':a;N;$!ba;s/AllowOverride None/AllowOverride All/2' /etc/httpd/conf/httpd.conf

Set required services are set to start on boot.

systemctl enable mariadb
systemctl enable httpd
systemctl enable postfix

Finally, reboot for all changes to take effect

reboot

Optional

Log File Rotation

If this is not done the log files will keep growing indefinitely.

nano /etc/logrotate.d/asterisk
/var/spool/mail/asterisk
/var/log/asterisk/full
/var/log/asterisk/dtmf
/var/log/asterisk/fail2ban {
        size 50M
        dateformat -%Y%m%d-%H
        missingok
        rotate 4
        #compress
        notifempty
        sharedscripts
        create 0640 asterisk asterisk
        postrotate
        /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null || true
        endscript
        su root root
}

Set daily log rotate script to run hourly.  Based on above settings they will rotate if larger than 50 MB.  The rotated file will be datestamped and include the hour.  The hourly part prevents duplicate file errors from occurring when multiple rotations are attempted on the same day.

cp /etc/cron.daily/logrotate /etc/cron.hourly

Firewall

systemctl enable firewalld
systemctl restart firewalld
firewall-cmd --permanent --zone=public --add-service={http,https}
firewall-cmd --permanent --zone=public --add-port=5060-5061/tcp
firewall-cmd --permanent --zone=public --add-port=5060-5061/udp
firewall-cmd --permanent --zone=public --add-port=10000-20000/udp
firewall-cmd --reload

TFTP

If you plan to use hardware SIP phones you will probably want to set up TFTP.

yum -y install tftp-server
nano /etc/xinetd.d/tftp

change server_args = -s /var/lib/tftpboot
to server_args = -s /tftpboot

change disable=yes
to disable=no

mkdir /tftpboot
chmod 777 /tftpboot
systemctl restart xinetd
firewall-cmd --permanent --zone=public --add-port=69/udp
firewall-cmd --reload

Test ODBC

odbcinst -s -q

Use username & password in /etc/freepbx.conf to test connectivity to the DB via ODBC. 

isql -v MySQL-asteriskcdrdb freepbxuser somepassword

Test asterisk ODBC access

asterisk -vvvr
CLI> odbc show

Misc. settings

Set php memory_limit = 256M .

sed -i 's/memory_limit = .*/memory_limit = 256M/g' /etc/php.ini
systemctl restart httpd
Sections: