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

Fusionpbx

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

Tested on:

CentOS v7
Freeswitch v1.6
FusionPBX v4.4
PostgreSQL v9.4
Apache v2.4
PHP v7.1

Assumptions:

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

Install Prerequisites

Ensure all required packages are installed. 

yum -y install epel-release && yum -y update
yum install git nano httpd memcached ghostscript libtiff-devel libtiff-tools at tftp-server

PHP

yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum -y install yum-plugin-replace

# This updates any existing default version PHP files
yum replace php-common --replace-with php71u-common

yum install php71u php71u-common php71u-pdo php71u-soap php71u-xml php71u-xmlrpc php71u-pgsql php71u-cli php71u-imap php71u-mcrypt php71u-gd php71u-opcache php71u-json

PostgreSQL

rpm -Uvh https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-3.noarch.rpm
yum -y install postgresql94-server postgresql94-contrib
/usr/pgsql-9.4/bin/postgresql94-setup initdb
systemctl enable postgresql-9.4
systemctl start postgresql-9.4

Setup client authentication to allow local connections.

nano +82 /var/lib/pgsql/9.4/data/pg_hba.conf
host  all all 127.0.0.1/32 trust
host  all all ::1/128      trust
systemctl restart postgresql-9.4

Test interactive terminal

sudo -u postgres psql
postgres=#
\q

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 -y install freeswitch-config-vanilla freeswitch-sounds* freeswitch-lang* freeswitch-lua freeswitch-xml-cdr

Create Databases and user

cd /tmp
password=somepassword
sudo -u postgres psql -c "CREATE DATABASE fusionpbx;"
sudo -u postgres psql -c "CREATE DATABASE freeswitch;"
sudo -u postgres psql -c "CREATE ROLE fusionpbx WITH SUPERUSER LOGIN PASSWORD '$password';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE fusionpbx to fusionpbx;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE freeswitch to fusionpbx;"

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=postgresql-9.4.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 httpd
systemctl enable freeswitch
systemctl enable memcached
systemctl restart httpd
systemctl restart freeswitch
systemctl restart memcached
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

Enable freeswitch database connection

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

nano +147 /etc/freeswitch/autoload_configs/switch.conf.xml
<param name="core-db-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=fusionpbx password='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
firewall-cmd --list-all

Daily Backup and housekeeping

Backup script

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

db_host=127.0.0.1
db_port=5432
now=$(date +%Y-%m-%d)
mkdir -p /var/backups/fusionpbx/postgresql

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

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

# Create databse backup
pg_dump --verbose -Fc --host=${db_host} --port=${db_port} -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql

# Combine and compress to create the main backup
tar -zvcf /var/backups/fusionpbx/backup_${now}.tgz /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_${now}.sql \
/var/www/html /usr/share/freeswitch/scripts /var/lib/freeswitch/storage \
/var/lib/freeswitch/recordings /etc/fusionpbx /etc/freeswitch
chmod +x /etc/cron.daily/fusionpbx-backup

Housekeeping script

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

# Delete freeswitch logs older 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 {} \;
#psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_voicemail_messages WHERE to_timestamp(created_epoch) < NOW() - INTERVAL '90 days'"

## Uncomment to delete call detail records older 90 days
#psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_xml_cdr WHERE start_stamp < NOW() - INTERVAL '90 days'"
chmod +x /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: