FusionPBX v4.4 Freeswitch v1.6 Debian v8 PostgreSQL Apache Install Guide


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

Tested on:

Debian v8 (Jessie) 64 bit
Freeswitch v1.6
FusionPBX v4
PostgreSQL v9.4
Apache v2.4
PHP v7.1


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

Install Prerequisites

Set server locale.  This should be done before PostgreSQL is installed.

# Select en_US.UTF-8 UTF-8
dpkg-reconfigure locales

Logout and log back in and check that LANG=en_US.UTF-8.


Install packages

apt update && apt upgrade -y && apt install lsb-release
apt -y install git nano dbus sudo apache2 curl memcached sqlite3 postgresql-9.4 postgresql-client-9.4 haveged ghostscript libtiff5-dev libtiff-tools at tftpd


# install this section one line at a time.

apt -y install apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt update && apt -y install php7.1 php7.1-cli php7.1-common php7.1-curl php7.1-mcrypt php7.1-pgsql php7.1-sqlite3 php7.1-odbc php7.1-xml php7.1-imap

Disable Selinux

Check status


If command exists and indicates it is 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

Set Timezone

Using tzselect is one way to find the correct timezone.

timedatectl set-timezone America/Vancouver
​timedatectl status

Also need to change php timezone

nano +939 /etc/php/7.1/apache2/php.ini
date.timezone = America/Vancouver
systemctl restart apache2



curl https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -

echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ $(lsb_release -sc) main" > \

apt update && apt -y install freeswitch-all freeswitch-all-dbg freeswitch-sounds* freeswitch-music* gdb


Check that localhost connections are allowed.  This is necessary for the backup script.

nano +92 /etc/postgresql/9.4/main/pg_hba.conf
host all all trust
systemctl restart postgresql

Check PostgreSQL locale

sudo -u postgres psql -l

If Encoding is not UTF8 and Collate & Ctype is not en_US.UTF8 then set it now.

sudo -u postgres psql

update pg_database set encoding = 6, datcollate = 'en_US.UTF8', datctype = 'en_US.UTF8' where datname = 'template0';
update pg_database set encoding = 6, datcollate = 'en_US.UTF8', datctype = 'en_US.UTF8' where datname = 'template1';

Create databases and user

cd /tmp
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;"


There may be enhancements and fixes in our version that are not be in the official repo.

# Makes sure to include the "." at the end.
cd /var/www/html
rm index.html
mkdir -p /etc/fusionpbx
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/

Set ownership and permissions

# Set ownership
chown -R freeswitch. /etc/freeswitch /etc/fusionpbx /var/lib/freeswitch \
/var/log/freeswitch /usr/share/freeswitch /var/www/html

# Set directory permissions to 770 (u=rwx,g=rwx,o='')
find /etc/freeswitch -type d -exec chmod 770 {} \;
find /etc/fusionpbx -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 {} \;

# Set file permissions to 664 (u=rw,g=rw,o=r)
find /etc/freeswitch -type f -exec chmod 664 {} \;
find /etc/fusionpbx -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 {} \;

Apache config

sed -i 's/\(APACHE_RUN_USER=\)\(.*\)/\1freeswitch/g' /etc/apache2/envvars
sed -i 's/\(APACHE_RUN_GROUP=\)\(.*\)/\1freeswitch/g' /etc/apache2/envvars
chown freeswitch. /run/lock/apache2
systemctl restart apache2


nano /etc/systemd/system/freeswitch.service
After=syslog.target network.target network-online.target
After=postgresql.service apache2.service

ExecStart=/usr/bin/freeswitch -ncwait -nonat $FREESWITCH_PARAMS
ExecReload=/usr/bin/kill -HUP $MAINPID


Create the $FREESWITCH_PARAMS file for extra parameters

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

Enable services

systemctl daemon-reload
systemctl enable freeswitch
systemctl restart freeswitch

Fix fs_cli

If fs_cli command does not work with freeswitch running change the following config line. 

nano +4 /etc/freeswitch/autoload_configs/event_socket.conf.xml
<param name="listen-ip" value=""/>
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
Browse to the public IP address of the server


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

Freeswitch uses sqlite by default.  This optional configuration changes that to use PostgreSQL.

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

Configure Firewall

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

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

# 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 {} \;
#psql --host= --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= --username=fusionpbx -c "delete from v_xml_cdr WHERE start_stamp < NOW() - INTERVAL '90 days'"
chmod +x /etc/cron.daily/fusionpbx-maintenance

Troubleshooting Lua

To view the dyamically generated xml files.

nano /usr/share/freeswitch/scripts/resources/config.lua
## Change debug options from false to true to see lua generated output in fs_cli
       debug["params"] = true;
       debug["sql"] = true;
       debug["xml_request"] = true;
       debug["xml_string"] = true;
       debug["cache"] = true;


If you plan to use hardware SIP phones you may want to enable TFTP.

Create tftp config

cat >> /etc/xinetd.d/tftp << EOF
service tftp
protocol        = udp
port            = 69
socket_type     = dgram
wait            = yes
user            = nobody
server          = /usr/sbin/in.tftpd
server_args     = /tftpboot
disable         = no


Make the directory and restart the daemon to start tftp.

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