ASTPP VoIP Billing v3.6 CentOS v7 Freeswitch v1.6 Apache Install Guide

This guide covers the installation of the ASTPP VoIP billing and Freeswitch applications.  ASTPP is installed manually from source.  Freeswitch is installed from RPMs.

Tested using the following software:

  • CentOS v7 minimal install
  • Freeswitch v1.6
  • ASTPP v3.6
  • Apache v2.4
  • PHP v7.1
  • MariaDB v5.5

Prerequisites

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

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 -y install php71u php71u-common php71u-pdo php71u-soap php71u-xml php71u-xmlrpc php71u-cli php71u-imap php71u-mcrypt php71u-gd php71u-opcache php71u-json php71u-mysqlnd php71u-odbc pear1u

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

Disable Firewall

It is sometimes helpful to disable the firewall during installation.

systemctl disable firewalld
systemctl disable iptables
systemctl stop firewalld
systemctl stop iptables

Timezone

## FIND YOUR TIMEZONE
tzselect

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

## CHECK TIMEZONE
​timedatectl status

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 freeswitch-application-curl freeswitch-xml-curl freeswitch-event-json-cdr

ASTPP

# Set ${password} variable.  This is used muliple times in this section.
password=somepassword
cd /usr/src
git clone -b v3.6 https://github.com/iNextrix/ASTPP.git
systemctl enable mariadb
systemctl restart mariadb
mysql -e "CREATE DATABASE astpp CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql -e "CREATE USER 'astppuser'@'localhost' IDENTIFIED BY '${password}';"
mysql -e "GRANT ALL PRIVILEGES ON astpp.* TO 'astppuser'@'localhost' WITH GRANT OPTION;"
mysql -e "FLUSH PRIVILEGES;"
mysql astpp < ASTPP/database/astpp-3.0.sql
mysql astpp < ASTPP/database/astpp-upgrade-3.5.sql
mysql astpp < ASTPP/database/astpp-upgrade-3.6.sql

ODBC

cat >> /etc/odbc.ini << EOF
[ASTPP]
Driver = MySQL
SERVER = 127.0.0.1
DATABASE = astpp
USERNAME = astppuser
PASSWORD = ${password}
PORT = 3306
OPTION = 67108864
Socket = /var/lib/mysql/mysql.sock
threading = 0
charset = utf8
EOF

Test odbc driver

odbcinst -s -q

Test odbc connection

isql -v astpp astppuser ${password} 
quit

Copy and configure Freeswitch files

cd /usr/src
cp -R ASTPP/freeswitch/fs /var/www/html/
cp -R ASTPP/freeswitch/scripts/* /usr/share/freeswitch/scripts/
cp -R ASTPP/freeswitch/sounds/*.wav /usr/share/freeswitch/sounds/en/us/callie/

rm -Rf /etc/freeswitch/dialplan/*
touch /etc/freeswitch/dialplan/astpp.xml
rm -Rf /etc/freeswitch/directory/*
touch /etc/freeswitch/directory/astpp.xml
rm -Rf /etc/freeswitch/sip_profiles/*
touch /etc/freeswitch/sip_profiles/astpp.xml

Copy and configure ASTPP files

cd /usr/src
mkdir -p /var/lib/astpp
cp ASTPP/config/astpp-config.conf /var/lib/astpp/astpp-config.conf
cp ASTPP/config/astpp.lua /var/lib/astpp/astpp.lua

# Copy/config web GUI files
cp -R ASTPP/web_interface/astpp /var/www/html/
cp ASTPP/web_interface/apache/astpp.conf /etc/httpd/conf.d/astpp.conf
cp ASTPP/web_interface/apache/astpp.conf /etc/httpd/conf.d/fs.conf
sed -i "s#8081#8735#g" /etc/httpd/conf.d/fs.conf
sed -i "s#astpp#fs#g" /etc/httpd/conf.d/fs.conf
mv /var/www/html/astpp/htaccess /var/www/html/astpp/.htaccess

# Copy ASTPP specific freeswitch config files
/bin/cp -R ASTPP/freeswitch/conf/autoload_configs/* /etc/freeswitch/autoload_configs/

# ASTPP links to Freeswitch use /usr/local by default.  Freeswitch RPMs use /usr/share.
sed -i "s#/usr/local/freeswitch/#/usr/share/freeswitch/#g" /etc/freeswitch/autoload_configs/lua.conf.xml
sed -i "s#/usr/local/freeswitch/#/usr/share/freeswitch/#g" /etc/freeswitch/autoload_configs/json_cdr.conf.xml
sed -i "s#/usr/local/freeswitch/#/usr/share/freeswitch/#g" /usr/share/freeswitch/scripts/astpp-callingcards.lua
sed -i "s#/usr/local/freeswitch/#/usr/share/freeswitch/#g" /usr/share/freeswitch/scripts/astpp/astpp.lua
sed -i "s#/usr/local/freeswitch/#/usr/share/freeswitch/#g" /usr/share/freeswitch/scripts/astpp/scripts/astpp.xml.lua

sed -i "s#\$\${base_dir}/recordings#\$\${recordings_dir}#g" /usr/share/freeswitch/scripts/astpp/scripts/astpp.xml.lua

# Configure ASTPP config files in /var/lib/astpp.
serverIP=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
sed -i "s#\(^dbname\).*#dbname = astpp#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^dbuser\).*#dbuser = astppuser#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^dbpass\).*#dbpass = ${password}#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^base_url\).*#base_url = http://${serverIP}:8081/#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^DB_USERNAME\).*#DB_USERNAME = \"astppuser\"#" /var/lib/astpp/astpp.lua
sed -i "s#\(^DB_PASSWD\).*#DB_PASSWD = \"${password}\"#" /var/lib/astpp/astpp.lua

CRON

crontab -u freeswitch -e
# I
# Generate Invoice   
0 1 * * * cd /var/www/html/astpp/cron/ && php cron.php GenerateInvoice
# Low balance notification
0 1 * * * cd /var/www/html/astpp/cron/ && php cron.php UpdateBalance
# Low balance notification
0 0 * * * cd /var/www/html/astpp/cron/ && php cron.php LowBalance        
# Update currency rate
0 0 * * * cd /var/www/html/astpp/cron/ && php cron.php CurrencyUpdate
# Email Broadcasting
* * * * * cd /var/www/html/astpp/cron/ && php cron.php BroadcastEmail

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

It is a good idea to run this anytime there are any changes/moves/adds/upgrades.

# 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

Configure php.ini

sed -i "s#short_open_tag = Off#short_open_tag = On#g" /etc/php.ini
sed -i "s#;cgi.fix_pathinfo=1#cgi.fix_pathinfo=1#g" /etc/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 3000/" /etc/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php.ini
sed -i "s/memory_limit = 128M/memory_limit = 512M/" /etc/php.ini

Lock down the database server

mysql_secure_installation
systemctl restart mariadb

Answer Y to everything.

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,8081}/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

Enable services

systemctl daemon-reload
systemctl enable mariadb
systemctl enable httpd
systemctl enable freeswitch
systemctl restart httpd
systemctl restart freeswitch
systemctl disable sendmail
systemctl stop sendmail
systemctl enable postfix
systemctl restart postfix

Test Freeswitch console

If fs_cli command is not working change the following line.

nano +4 /etc/freeswitch/autoload_configs/event_socket.conf.xml
<param name="listen-ip" value="127.0.0.1"/>
systemctl restart freeswitch

Browse to control panel

http://x.x.x.x:8081

username: admin
password: admin

The 8081 port can be changed at /var/lib/astpp/astpp-config.conf and  /etc/httpd/conf.d/astpp.conf. Remember to change the port on the firewall as well.

User documentation is located at the following link
http://astpp.readthedocs.io/en/v3.6/Modules/modules.html