FusionPBX v4.4 Freeswitch v1.6 CentOS v7 MariaDB Apache Install Guide

Fusionpbx

Fusionpbx is a full featured mult-tenant GUI for Freeswitch.  This guide covers the installation of Fusionpbx and Freeswitch® with MariaDB and Apache on CentOS v7. 

Tested on:

CentOS v7
Freeswitch v1.6
FusionPBX v4.4
MariaDB v5.5
Apache v2.4
PHP v7.1

Assumptions:

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

Prerequisites

yum -y update && yum -y install epel-release
yum install git nano httpd unixODBC mysql-connector-odbc memcached ghostscript libtiff-devel libtiff-tools at mariadb mariadb-server tftp-server

PHP

Install Repo

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

Install PHP v7.1

yum-config-manager --enable remi-php71
yum -y install php php-common php-pdo php-soap php-xml php-xmlrpc php-mysqlnd php-cli php-imap php-mcrypt php-gd php-odbc php-opcache php-json

Disable Selinux

Check status

sestatus

If not disabled, set SELINUX=disabled in /etc/selinux/config.  Requires reboot for changes to take effect.

sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config

Timezone

## FIND YOUR TIMEZONE
tzselect

## SET TIMEZONE EXAMPLE
timedatectl set-timezone America/Vancouver

## CHECK TIMEZONE
​timedatectl status

Memcached

Restrict memcached to localhost to prevent it from being used for DDoS attacks.

nano /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 127.0.0.1"

Install

Freeswitch

rpm -Uvh http://files.freeswitch.org/freeswitch-release-1-6.noarch.rpm
yum install freeswitch-config-vanilla freeswitch-sounds* freeswitch-lang* freeswitch-lua freeswitch-xml-cdr

Database

systemctl start mariadb
password=somepassword
mysql -e "CREATE DATABASE freeswitch;"
mysql -e "CREATE DATABASE fusionpbx;"
mysql -e "GRANT ALL PRIVILEGES ON freeswitch.* TO fusionpbx@localhost IDENTIFIED BY '$password';"
mysql -e "GRANT ALL PRIVILEGES ON fusionpbx.* TO fusionpbx@localhost IDENTIFIED BY '$password';"
mysql -e "flush privileges;"

ODBC

nano /etc/odbc.ini
[freeswitch]
Driver   = MySQL
SERVER   = 127.0.0.1
PORT     = 3306
DATABASE = freeswitch
OPTION  = 67108864
Socket   = /var/lib/mysql/mysql.sock
threading=0
MaxLongVarcharSize=65536

[fusionpbx]
Driver   = MySQL
SERVER   = 127.0.0.1
PORT     = 3306
DATABASE = fusionpbx
OPTION  = 67108864
Socket   = /var/lib/mysql/mysql.sock
threading=0

Test odbc driver

odbcinst -s -q

Test odbc connection

isql -v freeswitch fusionpbx somepassword 
quit

Download Fusionpbx

Make sure to include the . at the end.  There may be enhancements and fixes in our version that are not be in the official repo.

cd /var/www/html
git clone -b 4.4 https://github.com/powerpbx/fusionpbx.git .

Copy Directories

Replace default freeswitch conf files with fusionpbx conf files

mv /etc/freeswitch /etc/freeswitch.orig
mkdir /etc/freeswitch
cp -R /var/www/html/resources/templates/conf/* /etc/freeswitch

Copy music directories to default location

mkdir -p /usr/share/freeswitch/sounds/music/default
mv /usr/share/freeswitch/sounds/music/*000/ /usr/share/freeswitch/sounds/music/default/

Apache

# Add user freeswitch to group apache to avoid problems with /var/lib/php/sessions directory 
usermod -a -G apache freeswitch

# Set http server to run as same user/group as Freeswitch
sed -i "s/User apache/User freeswitch/" /etc/httpd/conf/httpd.conf
sed -i "s/Group apache/Group daemon/" /etc/httpd/conf/httpd.conf

# Set webserver to obey any .htaccess files in /var/www/html and subdirs 
sed -i ':a;N;$!ba;s/AllowOverride None/AllowOverride All/2' /etc/httpd/conf/httpd.conf

Set ownership and permissions

# Ownership
chown -R freeswitch.daemon /etc/freeswitch /var/lib/freeswitch \
/var/log/freeswitch /usr/share/freeswitch /var/www/html

# Directory permissions to 770 (u=rwx,g=rwx,o='')
find /etc/freeswitch -type d -exec chmod 770 {} \;
find /var/lib/freeswitch -type d -exec chmod 770 {} \;
find /var/log/freeswitch -type d -exec chmod 770 {} \;
find /usr/share/freeswitch -type d -exec chmod 770 {} \;
find /var/www/html -type d -exec chmod 770 {} \;

# File permissions to 664 (u=rw,g=rw,o=r)
find /etc/freeswitch -type f -exec chmod 664 {} \;
find /var/lib/freeswitch -type f -exec chmod 664 {} \;
find /var/log/freeswitch -type f -exec chmod 664 {} \;
find /usr/share/freeswitch -type f -exec chmod 664 {} \;
find /var/www/html -type f -exec chmod 664 {} \;

Systemd config

nano /etc/systemd/system/freeswitch.service
[Unit]
Description=FreeSWITCH
Wants=network-online.target
After=syslog.target network-online.target
After=mariadb.service httpd.service

[Service]
Type=forking
User=freeswitch
ExecStartPre=/usr/bin/mkdir -m 0750 -p /run/freeswitch
ExecStartPre=/usr/bin/chown freeswitch:daemon /run/freeswitch
WorkingDirectory=/run/freeswitch
PIDFile=/run/freeswitch/freeswitch.pid
EnvironmentFile=-/etc/sysconfig/freeswitch
ExecStart=/usr/bin/freeswitch -ncwait -nonat $FREESWITCH_PARAMS
ExecReload=/usr/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

Create the $FREESWITCH_PARAMS file for extra parameters.  If freeswitch was installed from RPM this will probably already exist.

nano /etc/sysconfig/freeswitch
## Type:                string
## Default:             ""
## Config:              ""
## ServiceRestart:      freeswitch
#
# if not empty: parameters for freeswitch
#
FREESWITCH_PARAMS=""

Enable services

systemctl daemon-reload
systemctl enable mariadb
systemctl enable httpd
systemctl enable memcached
systemctl enable freeswitch
systemctl restart memcached
systemctl restart httpd
systemctl restart freeswitch
Reboot and browse to the public IP address of the server

 http://xx.xx.xx.xx 

to complete the install using the following:

Username: superadmin (or whatever you want)
Password: somepassword (use whatever you want)

Database Name: fusionpbx
Database Username: fusionpbx
Database Password: somepassword
Create Database Options: uncheck
Create Database Username:
Create Database Password : 

It will take several minutes to complete. Post install tasks are mandatory.

Post Install

Lock down MySQL

mysql_secure_installation
systemctl restart mariadb

Answer Y to everything.

Enable freeswitch database connection

This optional configuration sets Freeswitch to use mysql instead of sqlite for storing internal data.

nano +147 /etc/freeswitch/autoload_configs/switch.conf.xml
<param name="core-db-dsn" value="freeswitch:fusionpbx:somepassword" /> 
systemctl restart freeswitch

Change Voicemail to Email app configuration

nano +119 /etc/freeswitch/autoload_configs/switch.conf.xml
<param name="mailer-app" value="/usr/bin/php /var/www/html/secure/v_mailto.php"/>
                <param name="mailer-app-args" value="-t"/>
systemctl restart freeswitch

Configure firewall

yum -y install firewalld
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --permanent --zone=public --add-service={http,https}
firewall-cmd --permanent --zone=public --add-port={5060,5061,5080,5081}/tcp
firewall-cmd --permanent --zone=public --add-port={5060,5061,5080,5081}/udp
firewall-cmd --permanent --zone=public --add-port=16384-32768/udp
firewall-cmd --reload

Daily Backup and housekeeping

Backup script

nano /etc/cron.daily/fusionpbx-backup
#!/bin/sh

# set up variables
NOW=$(date +%Y-%m-%d)
DATABASE=fusionpbx
USER=fusionpbx
PASS=somepassword
mkdir -p /var/backups/fusionpbx/mysql

# Delete mysql backups if older than 4 days
find /var/backups/fusionpbx/mysql/fusionpbx_mysql* -mtime +4 -exec rm {} \;

# Delete the main backup if older than 4 days
find /var/backups/fusionpbx/*.tgz -mtime +4 -exec rm {} \;

# do the mysql database backup
/usr/bin/mysqldump --opt --user=${USER} --password=${PASS} ${DATABASE} > /var/backups/fusionpbx/mysql/fusionpbx_mysql_${NOW}.sql

# Combine and compress to create the main backup
tar -zvcf /var/backups/fusionpbx/backup_${NOW}.tgz /var/backups/fusionpbx/mysql/fusionpbx_mysql_${NOW}.sql \
/var/www/fusionpbx /usr/share/freeswitch/scripts /var/lib/freeswitch/storage \
/var/lib/freeswitch/recordings /etc/fusionpbx /etc/freeswitch
chmod 755 /etc/cron.daily/fusionpbx-backup

Housekeeping script

nano /etc/cron.daily/fusionpbx-maintenance
#!/bin/sh

DATABASE=fusionpbx
USER=fusionpbx
PASS=somepassword

# Delete freeswitch logs older than 7 days
find /var/log/freeswitch/freeswitch.log.* -mtime +7 -exec rm {} \;

# Delete call recordings older than 90 days
find /var/lib/freeswitch/recordings/*/archive/*  -name '*.wav' -mtime +90 -exec rm {} \;
find /var/lib/freeswitch/recordings/*/archive/*  -name '*.mp3' -mtime +90 -exec rm {} \;

## Uncomment to delete faxes older than 90 days 
#find /var/lib/freeswitch/storage/fax/*  -name '*.tif' -mtime +90 -exec rm {} \; 
#find /var/lib/freeswitch/storage/fax/*  -name '*.pdf' -mtime +90 -exec rm {} \; 

## Uncomment to delete voicemails older than 90 days
#find /var/lib/freeswitch/storage/voicemail/default/*  -name 'msg_*.wav' -mtime +90 -exec rm {} \;
#find /var/lib/freeswitch/storage/voicemail/default/*  -name 'msg_*.mp3' -mtime +90 -exec rm {} \;
# /usr/bin/mysql -u ${USER} -p ${PASS} ${DATABASE} -e "DELETE FROM  v_voicemail_messages WHERE search_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY));"

## Uncomment to delete CDRs older than 90 days
# /usr/bin/mysql -u ${USER} -p ${PASS} ${DATABASE} -e "DELETE FROM  v_xml_cdr WHERE search_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY));"
chmod 755 /etc/cron.daily/fusionpbx-maintenance

TFTP

If you plan to use hardware SIP phones you may want to set up TFTP provisioning. 

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

Now go to GUI Advanced > Default Settings > Provision.  About 20 rows down set enabled = True.

Add a new Subcategory in Provision category by pressing the + icon and fill in as follows:

Category = provision
Subcategory = path
type = text
Value = /tftpboot
Enabled = True

 

Sections: