ASTPP VoIP Billing v3.6 Debian v8 Freeswitch v1.6 Nginx Install Guide

ASTPP

 

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

Tested using the following software:

  • Debian v8 (Jessie) x64 minimal install
  • ASTPP v3.6
  • Freeswitch v1.6
  • Nginx v1.6
  • PHP v7.1
  • MariaDB v10

Prerequisites

apt update && apt upgrade -y && apt -y remove apache2
apt -y install git nano dbus sudo nginx curl sqlite3 haveged ghostscript lsb-release libtiff5-dev libtiff-tools at dirmngr postfix gawk dnsutils openssl ntp libmyodbc unixodbc unixodbc-bin gettext fail2ban

PHP

# 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-fpm php7.1-gd php7.1-opcache php7.1-cli php7.1-common php7.1-curl php7.1-sqlite3 php7.1-odbc php7.1-mysql php7.1-xml php7.1-mcrypt php7.1-json php-pear

ODBC

cd /usr/src
wget https://downloads.mariadb.com/Connectors/odbc/connector-odbc-3.0.3/\
mariadb-connector-odbc-3.0.3-ga-debian-x86_64.tar.gz
tar -zxvf mariadb-connector-odbc-3.0.3*.tar.gz
cp mariadb-connector-odbc-3.0.3*/lib/libmaodbc.so /usr/lib/x86_64-linux-gnu/odbc/

Create /etc/odbcinst.ini

cat >> /etc/odbcinst.ini << EOF
[MySQL]
Description = ODBC for MariaDB
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1
  
EOF

MariaDB

# Set MariaDB root password when asked. Otherwise it will keep nagging.

apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
apt update && apt -y install mariadb-server
nano /etc/mysql/my.cnf
# Add the following line under [mysqld] to disable strict mode.
sql_mode=''
systemctl restart mariadb

Disable Selinux

Check status

sestatus

If the command is found and 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

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
systemctl restart rsyslog

Install

Freeswitch

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" > \
/etc/apt/sources.list.d/freeswitch.list

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

ASTPP

# Set MariaDB user ${userpassword} variable.  This is used muliple times in this section.
userpassword=somepassword

# Set MariaDB root password to whatever it was previously set to.
mysqlpassword=existingmysqlpassword
cd /usr/src
git clone -b v3.6 https://github.com/iNextrix/ASTPP.git
mysql -p${mysqlpassword} -e "CREATE DATABASE astpp CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql -p${mysqlpassword} -e "CREATE USER 'astppuser'@'localhost' IDENTIFIED BY '${userpassword}';"
mysql -p${mysqlpassword} -e "GRANT ALL PRIVILEGES ON astpp.* TO 'astppuser'@'localhost' WITH GRANT OPTION;"
mysql -p${mysqlpassword} -e "FLUSH PRIVILEGES;"
mysql -p${mysqlpassword} astpp < ASTPP/database/astpp-3.0.sql
mysql -p${mysqlpassword} astpp < ASTPP/database/astpp-upgrade-3.5.sql
mysql -p${mysqlpassword} 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 = ${userpassword}
PORT = 3306
OPTION = 67108864
Socket = /run/mysqld/mysqld.sock
threading = 0
charset = utf8

EOF

Test odbc driver

odbcinst -s -q

Test odbc connection

isql -v astpp astppuser ${userpassword} 
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 /usr/local/astpp
mkdir -p /var/log/astpp
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/nginx/deb_astpp.conf /etc/nginx/sites-available/astpp.conf
cp ASTPP/web_interface/nginx/deb_fs.conf /etc/nginx/sites-available/fs.conf

sed -i "s/client_max_body_size 8M/client_max_body_size 20M/" /etc/nginx/sites-available/astpp.conf
sed -i '35i fastcgi_read_timeout 300;' /etc/nginx/sites-available/astpp.conf
sed -i "s#php7.0#php7.1#" /etc/nginx/sites-available/astpp.conf
sed -i "s#php7.0#php7.1#" /etc/nginx/sites-available/fs.conf

ln -s /etc/nginx/sites-available/astpp.conf /etc/nginx/sites-enabled/astpp.conf 
ln -s /etc/nginx/sites-available/fs.conf /etc/nginx/sites-enabled/fs.conf 
rm /etc/nginx/sites-enabled/default

# Add nginx log files
touch /var/log/nginx/astpp_access.log
touch /var/log/nginx/astpp_error.log
touch /var/log/nginx/fs_access.log
touch /var/log/nginx/fs_error.log

# Add ASTPP log file
touch /var/log/astpp/astpp.log

# 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 binary packages 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

# Configure ASTPP config files in /var/lib/astpp.
serverIP=$(ifconfig | sed -En 's/127.0.0.*//;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 = ${userpassword}#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^base_url\).*#base_url = http://${serverIP}:8089/#" /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 = \"${userpassword}\"#" /var/lib/astpp/astpp.lua

CRON

crontab -u www-data -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

Systemd

Create unit file.

systemctl stop freeswitch
rm -r /run/freeswitch
nano /etc/systemd/system/freeswitch.service
[Unit]
Description=freeswitch
After=syslog.target network.target local-fs.target mariadb.service

[Service]
Type=forking
RuntimeDirectory=freeswitch
PIDFile=/run/freeswitch/freeswitch.pid
Environment="DAEMON_OPTS=-ncwait -nonat"
EnvironmentFile=-/etc/default/freeswitch
ExecStart=/usr/bin/freeswitch $DAEMON_OPTS
TimeoutSec=45s
Restart=always

User=www-data
Group=www-data
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=60000
LimitSTACK=250000
LimitRTPRIO=infinity
LimitRTTIME=infinity
IOSchedulingClass=realtime
IOSchedulingPriority=2
CPUSchedulingPriority=89
UMask=0007

; Comment this out if using OpenVZ
CPUSchedulingPolicy=rr

[Install]
WantedBy=multi-user.target

Create environment file.

cat >> /etc/default/freeswitch << EOF
# Uncommented variables will override variables in unit file
# User=""
# Group=""
# DAEMON_OPTS=""

EOF

Set ownership and permissions

Run this any time there are any changes/moves/adds/upgrades or if experiencing problems.

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

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

# 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 {} \;
find /var/log/astpp -type d -exec chmod 664 {} \;

Configure php-fpm

sed -i "s/;request_terminate_timeout = 0/request_terminate_timeout = 300/" /etc/php/7.1/fpm/pool.d/www.conf
sed -i "s#short_open_tag = Off#short_open_tag = On#g" /etc/php/7.1/fpm/php.ini
sed -i "s#;cgi.fix_pathinfo=1#cgi.fix_pathinfo=1#g" /etc/php/7.1/fpm/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 3000/" /etc/php/7.1/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php/7.1/fpm/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php/7.1/fpm/php.ini
sed -i "s/memory_limit = 128M/memory_limit = 512M/" /etc/php/7.1/fpm/php.ini
systemctl restart php7.1-fpm
systemctl restart nginx

Configure firewall

apt -y install firewalld
systemctl enable firewalld
systemctl start firewalld

firewall-cmd --permanent --zone=public --add-port={5060,5061,8089}/tcp
firewall-cmd --permanent --zone=public --add-port={5060,5061}/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 freeswitch
systemctl restart freeswitch

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:8089

username: admin
password: admin

The 8089 port can be changed at /var/lib/astpp/astpp-config.conf and  /etc/nginx/sites-available/astpp.conf. Remember to change the port on the firewall as well.  If accessing by DNS name change the IP to the DNS name.

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

 

Sections: