FreePBX 16, Asterisk 20, IAXModem 1.3.4 AvantFax 3.4.0 Hylafax+ 7.0.7 PHP 7.4 Installation

Hello everybody,

I’m please to release this guide to setup FreePBX 16 with Asterisk 20, IAXModem 1.3.4, AvantFax 3.4.0, Hylaxfax+ 7.0.7, and PHP 7.4.

This is an update from my originally posted guides here (2011) >> ***UPDATE*** Asterisk 1.8.7.1, FreePBX 2.8.1, HylaFAX 6.0.5, AvantFAX 3.3.3, IAXModem 1.2.0, A2Billing 1.9.4 ***WORKING*** and here (2020) >> ***UPDATE*** Asterisk 16, FreePBX 14, Hylafax 7, Avantfax 3.3.5, IAX Modem 1.2.0 ***WORKING*** and now 2023 wow how times flies!

Recently AvantFax released an update from 3.3.7 to 3.4.0 that allows PHP7 compatibility.

This is a setup script I use to install on my local machines or VM’s This assumes a clean installation of Ubuntu 20.04 and are root user. You may also use 22 or 23.

All of the files used in this script are downloaded from my server and updated periodically.

REMEMBER TO EDIT THE username AND password WITH RESPECTIVE USERNAMES AND PASSWORDS AND TO SET YOUR SETTINGS FOR THE FOLLOWING

Hostname
Certificate
Turn Server
MySQL
Asterisk Config Files

I would strongly suggest you read through this whole script to identity any places where you need to substitute and change the information.

Without further delay…

Asterisk 20.4.0
FreePBX 16
AvantFax 3.4.0
IAXModem 1.3.4
HylaFax 7.0.7
PHP 7.4

Ubuntu 20.04
10/16/2023

cd /usr/src

#System Update
apt update && apt -y upgrade

#Disable Firewall & Reboot
systemctl stop ufw
systemctl disable ufw
systemctl stop iptables
systemctl disable iptables
systemctl stop ip6tables
systemctl disable ip6tables
iptables -F
reboot

#Dependencies
apt -y install software-properties-common git maven build-essential debhelper net-tools unzip git gnupg2 curl libnewt-dev libssl-dev libncurses5-dev subversion libsqlite3-dev libjansson-dev libxml2-dev uuid-dev subversion

download Package
cd /usr/src
wget https://acscorp.us/files/asterisk/install-ubuntu.zip
unzip install-ubuntu.zip

#Install Webmin
dpkg -i webmin_current.deb
apt -fy install

#Set Hostname
hostnamectl set-hostname host.domain.tld --static

#Edit Hosts
nano /etc/hosts

127.0.0.1 localhost.localdomain localhost
192.168.1.2 host.domain.tld host

#Add Asterisk User
groupadd asterisk
useradd -r -d /var/lib/asterisk -g asterisk asterisk
usermod -aG audio,dialout,sudo asterisk

#Add PATH
tee /etc/ld.so.conf.d/asterisk.conf<<EOF
/usr/lib64
EOF

ldconfig

#Add PHP Repositories
add-apt-repository -y ppa:ondrej/php

#Update Packages
apt update && apt -y upgrade

#Dependencies
apt -y install apache2 python3-certbot-apache openssh-server mariadb-client bison flex php7.4-cli php7.4-intl mpg123 libxml2-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf unixodbc-dev uuid uuid-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libcurl4-openssl-dev libical-dev libneon27-dev libsrtp2-dev sudo subversion libtool-bin python2-dev unixodbc dirmngr debhelper-compat cmake apache2 libapache2-mod-php7.4 php7.4 php-pear php7.4-cgi php7.4-ldap php7.4-common php7.4-curl php7.4-mbstring php7.4-gd php7.4-mysql php7.4-bcmath php7.4-zip php7.4-xml php7.4-imap php7.4-json php7.4-snmp php7.4-fpm libglib2.0-dev bind9 sox incron linux-source ffmpeg odbc-mariadb libmariadb3 python3-dev default-libmysqlclient-dev build-essential mariadb-server flite flac #libspandsp-dev

systemctl start apache2 mariadb
systemctl enable apache2 mariadb
mysql_secure_installation

#Disable systemd-resolved Stub
sudo sed -r -i.orig ‘s/#?DNSStubListener=yes/DNSStubListener=no/g’ /etc/systemd/resolved.conf
systemctl stop systemd-resolved
sudo unlink /etc/resolv.conf
echo -e “nameserver 192.168.1.1” | sudo tee /etc/resolv.conf #CHANGE NAMESERVER ie 127.0.0.1

cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig

sed -i ‘s/(^upload_max_filesize = )./\1512M/’ /etc/php/7.4/cli/php.ini
sed -i 's/(^memory_limit = ).
/\1512M/’ /etc/php/7.4/cli/php.ini
sed -i ‘s/(^post_max_size = ).*/\1256M/’ /etc/php/7.4/cli/php.ini

sed -i ‘s/^(User|Group).*/\1 asterisk/’ /etc/apache2/apache2.conf
sed -i ‘s/AllowOverride None/AllowOverride All/’ /etc/apache2/apache2.conf

a2enmod proxy_fcgi setenvif
a2enmod rewrite
a2enconf php7.4-fpm
systemctl restart apache2

cd /usr/src
mkdir -p /etc/apt/keyrings
apt update && apt -y install ca-certificates curl gnupg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo “deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main” | sudo tee /etc/apt/sources.list.d/nodesource.list
apt update && apt -y install nodejs

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list
apt update
apt -y install yarn python3-pip
pip install setuptools

#Install DAHDI Linux Complete
cd /usr/src
tar zxf dahdi-linux-complete-3.2.0+3.2.0.tar.gz
cd dahdi-linux-complete-3.2.0+3.2.0
make
make install
make install-config

cd …
tar zxf libpri-1.6.0.tar.gz
cd libpri-1.6.0
make && make install

cd …
tar zxf asterisk-perl-1.08.tar.gz
cd asterisk-perl-1.08
perl Makefile.PL
make all
make install

cd …
git clone GitHub - innotelinc/spandsp: SpanDSP is a low-level signal processing library that modulates and demodulates signals commonly used in telephony, such as the "noise" generated by a fax modem or DTMF touchpad.
cd spandsp
./bootstrap.sh && ./configure && make && make install
ldconfig

cd …
tar jxf mpg123-1.32.3.tar.bz2
cd mpg123-1.32.3
./configure --libdir=/usr/lib64 && make && make install
ln -s /usr/local/bin/mpg123 /usr/bin/mpg123

cd …
tar zxf lame-3.100.tar.gz
cd lame-3.100
./configure --libdir=/usr/lib64 && make && make install
ln -s /usr/local/bin/lame /usr/bin/lame

cd …
tar zxf texinfo-7.0.3.tar.gz
cd texinfo-7.0.3
./configure --libdir=/usr/lib64 && make && make install

cd …
unzip iksemel-1.4-master.zip
cd iksemel-1.4-master
./autogen.sh
./configure --libdir=/usr/lib64 && make && make install

cd …
tar zxf libsrtp-2.5.0.tar.gz
cd libsrtp-2.5.0
./configure --libdir=/usr/lib64 --enable-openssl && make && make install
echo “/usr/local/include” > /etc/ld.so.conf.d/srtp.conf
ldconfig

cd …
tar zxf sqlite-autoconf-3430100.tar.gz
cd sqlite-autoconf-3430100
./configure --libdir=/usr/lib64 && make && make install
ldconfig

asterisk 20
cd …
tar zxf asterisk-20-current.tar.gz
cd asterisk-20.*
contrib/scripts/install_prereq install
./configure --libdir=/usr/lib64 --with-crypto --with-ssl --with-mysqlclient --with-srtp --with-sqlite3 --with-jansson-bundled --with-pjproject-bundled
make menuselect.makeopts
menuselect/menuselect --enable res_config_mysql menuselect.makeopts
menuselect/menuselect --enable format_mp3 menuselect.makeopts
menuselect/menuselect --enable app_saycounted menuselect.makeopts
menuselect/menuselect --enable app_macro menuselect.makeopts
menuselect/menuselect --enable smsq menuselect.makeopts
menuselect/menuselect --enable stereorize menuselect.makeopts
menuselect/menuselect --enable streamplayer menuselect.makeopts
menuselect/menuselect --enable chan_sip menuselect.makeopts
menuselect/menuselect --enable check_expr menuselect.makeopts
menuselect/menuselect --enable check_expr2 menuselect.makeopts
menuselect/menuselect --enable codec_opus menuselect.makeopts
menuselect/menuselect --enable codec_silk menuselect.makeopts
menuselect/menuselect --enable codec_siren7 menuselect.makeopts
menuselect/menuselect --enable codec_siren14 menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-WAV menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-ULAW menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-ALAW menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-GSM menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-G729 menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-G722 menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-SLN16 menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-SIREN7 menuselect.makeopts
menuselect/menuselect --enable CORE-SOUNDS-EN-SIREN14 menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-WAV menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-ULAW menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-ALAW menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-GSM menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-G729 menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-G722 menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-SLN16 menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-SIREN7 menuselect.makeopts
menuselect/menuselect --enable MOH-OPSOUND-SIREN14 menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-WAV menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-ULAW menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-ALAW menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-GSM menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-G729 menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-G722 menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-SLN16 menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-SIREN7 menuselect.makeopts
menuselect/menuselect --enable EXTRA-SOUNDS-EN-SIREN14 menuselect.makeopts
contrib/scripts/get_mp3_source.sh
make && make install && make samples && make config
ldconfig

#Edit
nano /etc/asterisk/asterisk.conf
runuser = asterisk ; The user to run as.
rungroup = asterisk ; The group to run as.

#Install Stun & VPN Server
cd /usr/src

apt -y install python3 python3-venv libaugeas0 easy-rsa flite python3-pip coturn

apt -y autoremove
apt -y remove certbot

python3 -m venv /opt/certbot/
/opt/certbot/bin/pip install --upgrade pip
/opt/certbot/bin/pip install certbot certbot-apache
ln -s /opt/certbot/bin/certbot /usr/bin/certbot

#Edit httpd.conf

<Directory “/var/www/html”>
allow from all
Options FollowSymLinks
AllowOverride All
Require all granted

#Get Turn Server Certificate
certbot --apache --preferred-chain “ISRG Root X1” --email [email protected] --agree-tos --no-eff-email -d host.domain.tld

mkdir -p /etc/coturn
cp /etc/letsencrypt/live/host.domain.tld/fullchain.pem /etc/coturn/cert.pem
cp /etc/letsencrypt/live/host.domain.tld/privkey.pem /etc/coturn
chown turnserver:turnserver /etc/coturn/cert.pem
chown turnserver:turnserver /etc/coturn/privkey.pem

rm /etc/turnserver.conf
tee /etc/turnserver.conf<<EOF

Coturn TURN SERVER configuration file

listening-port=3478
tls-listening-port=5349
alt-listening-port=3479
alt-tls-listening-port=5350
fingerprint
lt-cred-mech
user=username:password
server-name=host.domain.tld
realm=host.domain.tld
cert=/etc/coturn/cert.pem
pkey=/etc/coturn/privkey.pem
cipher-list=“DEFAULT”
log-file=/var/log/coturn/turnserver.log
simple-log
cli-password=password
web-admin
web-admin-ip=IPaddress
web-admin-port=8833
#web-admin-listen-on-workers
EOF

turnadmin -A -u username -p password -r host.domain.tld

mkdir -p /var/log/coturn/
chown -R turnserver:turnserver /var/log/coturn

usermod -a -G root turnserver
systemctl enable coturn
systemctl start coturn

#Install WireGuard
cd /usr/src
curl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh
chmod +x wireguard-install.sh
./wireguard-install.sh

#Install WireGuard UI
cd /usr/src
wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz
tar -C /usr/local -xvf go1.21.1.linux-amd64.tar.gz

tee -a ~/.profile<<EOF
export PATH=$PATH:/usr/local/go/bin
EOF

source ~/.profile

git clone GitHub - ngoduykhanh/wireguard-ui: Wireguard web interface
cd wireguard-ui
#npm install -g yarn
./prepare_assets.sh
go build -o wireguard-ui

#Install Startup
systemctl enable [email protected]

cd /etc/systemd/system/
cat << EOF > wgui.service
[Unit]
Description=Restart WireGuard
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart [email protected]

[Install]
RequiredBy=wgui.path
EOF

cat << EOF > wgui.path
[Unit]
Description=Watch /etc/wireguard/wg0.conf for changes

[Path]
PathModified=/etc/wireguard/wg0.conf

[Install]
WantedBy=multi-user.target
EOF

cat << EOF > wgui.dashboard.service
[Unit]
Description=WireGuard Dashboard
After=network.target

[Service]
ExecStart=/usr/src/wireguard-ui/wireguard-ui
Restart=always

[Install]
WantedBy=multi-user.target
EOF

#Start WireGuard
systemctl enable wgui.{path,service,dashboard}
systemctl start wgui.{path,service,dashboard}

#Accessible
http://localhost:5000
admin/admin

#Install g723 & g729 Codec

#For Server Info
cat /proc/cpuinfo

systemctl enable dahdi
systemctl start dahdi

systemctl enable apache2
systemctl start apache2
systemctl enable named
systemctl start named
systemctl enable mariadb
systemctl start mariadb

download g723/9 Codecs

cd /usr/lib64/asterisk/modules
wget -O codec_g723.so http://asterisk.hosting.lv/bin/codec_g723-ast180-gcc4-glibc-x86_64-pentium4.so
wget -O codec_g729.so http://asterisk.hosting.lv/bin/codec_g729-ast180-gcc4-glibc-x86_64-pentium4.so

chmod +x codec_g723.so
chmod +x codec_g729.so
chown asterisk:asterisk codec_g723.so
chown asterisk:asterisk codec_g729.so

asterisk -rx ‘module load codec_g723.so’
asterisk -rx ‘module load codec_g729.so’
fwconsole restart

#Check Codec
asterisk -rx “core show translation recalc 10”

#Compile g729 Codec Only
cd /usr/src
apt -y remove cmake
mv cmake-3.26.5-linux-x86_64.sh /opt
cd /opt
chmod +x cmake-3.26.5-linux-x86_64.sh
./cmake-3.26.5-linux-x86_64.sh
ln -s /opt/cmake-3.26.5-linux-x86_64/bin/* /usr/bin

cd /usr/src
git clone GitHub - innotelinc/bcg729: Linphone.org mirror for bcg729 (git://git.linphone.org/bcg729.git)
cd bcg729
cmake .
make
make install

cd …
git clone GitHub - arkadijs/asterisk-g72x: G.729 and G.723.1 codecs for Asterisk
cd asterisk-g72x
./autogen.sh
./configure --libdir=/usr/lib64 --with-bcg729 --with-asterisk-includes=/usr/src/asterisk-20.4.0/include/
make && make install

cd /usr/lib64/asterisk/modules
chmod +x codec_g729.so
chown asterisk:asterisk codec_g729.so
asterisk -rx ‘module load codec_g729.so’
fwconsole restart

#Check Codec
asterisk -rx “core show translation recalc 10”

#Set Permissions
chown -R asterisk:asterisk /var/lib/php/sessions
chown -R asterisk:asterisk /var/spool/asterisk/*
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib64/asterisk

#Install FreePBX 16.0
cd /usr/src
tar zxf freepbx-16.0-latest.tgz
cd freepbx

mysqladmin -p create asterisk

mysqladmin -p create asteriskcdrdb

mysql -p

GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asterisk@localhost IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON asterisk.* TO asterisk@localhost IDENTIFIED BY ‘password’;
flush privileges;
\q

pear channel-update pear.php.net
pear install DB MDB2 MDB2 MDB2#mysql MDB2#mysqli MDB2#sqlite

cd /usr/src
tar zxf mariadb-connector-odbc-3.1.19-ubuntu-focal-amd64.tar.gz
cd mariadb-connector-odbc-3.1.19-ubuntu-focal-amd64
install lib/mariadb/libmaodbc.so /usr/lib64/
install -d /usr/lib64/mariadb/
install -d /usr/lib64/mariadb/plugin/
install lib/mariadb/plugin/caching_sha2_password.so /usr/lib64/mariadb/plugin/
install lib/mariadb/plugin/client_ed25519.so /usr/lib64/mariadb/plugin/
install lib/mariadb/plugin/dialog.so /usr/lib64/mariadb/plugin/
install lib/mariadb/plugin/mysql_clear_password.so /usr/lib64/mariadb/plugin/
install lib/mariadb/plugin/sha256_password.so /usr/lib64/mariadb/plugin/
systemctl restart mariadb

tee /usr/src/odbc_template.ini<<EOF
[MySQL]
Description = ODBC for MySQL (MariaDB)
Driver = /usr/lib64/libmaodbc.so
FileUsage = 1
EOF

cd /usr/src
odbcinst -i -d -n MariaDB -f odbc_template.ini

tee /etc/odbc.ini<<EOF
[MySQL-asteriskcdrdb]
Description=MySQL connection to ‘asteriskcdrdb’ database
driver=MySQL
server=localhost
database=asteriskcdrdb
username=root
password=password
Port=3306
Socket=/run/mysqld/mysqld.sock
option=3
Charset=utf8
EOF

tee /etc/asterisk/cdr_adaptive_odbc.conf<<EOF
[asteriskcdrdb]
connection=asteriskcdrdb
loguniqueid=1
table=cdr
alias start => calldate
EOF

tee /etc/asterisk/res_odbc_additional.conf<<EOF
[asteriskcdrdb]
enabled=>yes
dsn=>MySQL-asteriskcdrdb
pre-connect=>yes
max_connections=>5
username=>asterisk
password=>password
database=>asteriskcdrdb
EOF

systemctl restart mariadb

ln -s /var/run/asterisk /var/lib/asterisk/run
rm -rf /var/lib/asterisk/mohmp3/moh
ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3

ldconfig

#Install FreePBX
cd /usr/src/freepbx
rm -rf /var/www/html/index.html
./start_asterisk start
./install -n --dbuser=asterisk --dbpass=password --dbhost=127.0.0.1

#Install PM2 & UCP
npm install -g n
n install 8
hash -r
fwconsole chown
fwconsole ma downloadinstall pm2
fwconsole ma downloadinstall ucp
fwconsole restart

sed -i ‘s";[radius]"[radius]"g’ /etc/asterisk/cdr_general_custom.conf
sed -i ‘s";radiuscfg => /usr/local/etc/radiusclient-ng/radiusclient.conf"radiuscfg => /etc/radcli/radiusclient.conf"g’ /etc/asterisk/cdr_general_custom.conf
sed -i ‘s";radiuscfg => /usr/local/etc/radiusclient-ng/radiusclient.conf"radiuscfg => /etc/radcli/radiusclient.conf"g’ /etc/asterisk/cel.conf

tee /etc/logrotate.d/asterisk<<EOF
/var/log/asterisk/queue_log
/var/spool/mail/asterisk
/var/log/asterisk/freepbx_debug.log
/var/log/asterisk/messages
/var/log/asterisk/event_log
/var/log/asterisk/full
/var/log/asterisk/dtmf
/var/log/asterisk/fail2ban {
weekly
missingok
rotate 5
#compress
notifempty
sharedscripts
create 0640 asterisk asterisk
postrotate
/usr/sbin/asterisk -rx ‘logger reload’ > /dev/null 2> /dev/null || true
endscript
}
EOF

tee /etc/systemd/system/freepbx.service<<EOF
[Unit]
Description=FreePBX VoIP Server
After=mariadb.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start -q
ExecStop=/usr/sbin/fwconsole stop -q
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable freepbx

mkdir -p /var/www/html/admin/modules/_cache
chmod 777 /etc/amportal.conf
chmod 777 /etc/freepbx.conf
chown -R asterisk:asterisk /var/lib/php/sessions
chown -R asterisk:asterisk /var/spool/asterisk/*
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib64/asterisk
chown -R asterisk. /var/www/html

#Enable CDR Logging in Advanced Settings#

#Edit Asterisk IAX2 Settings Add Other Options in FreePBX
calltokenoptional = 0.0.0.0/0.0.0.0
maxcallnumbers = 16382
requirecalltoken = no

tee /etc/asterisk/rtp_additional.conf<<EOF
[general]
rtpstart=10002
rtpend=20000
rtpchecksums=yes
strictrtp=yes
stunaddr=host.domain.tld
turnaddr=host.domain.tld
turnusername=username
turnpassword=password
EOF

service apache2 restart

#Install Tesseract
apt -y install libleptonica-dev liblept5 exactimage html2ps

cd /usr/src
tar zxf tesseract-4.1.1.tar.gz
cd tesseract-4.1.1
./autogen.sh
./configure --libdir=/usr/lib64 && make && make install

cd /usr/local/share/tessdata/
mv /usr/src/eng.traineddata .

#Install IAXModem 1.3.4
cd /usr/src
tar zxf iaxmodem-1.3.4.tar.gz
cd iaxmodem-1.3.4
./configure --libdir=/usr/lib64
make
mkdir -p /etc/iaxmodem
mkdir -p /var/log/iaxmodem
cp iaxmodem /usr/local/sbin/

nano /etc/iaxmodem/ttyIAX1

device /dev/ttyIAX1
owner uucp:uucp
mode 660
port 4570
refresh 60
server 127.0.0.1
peername 5555551212
secret password
codec ulaw
cidname Fax Server
cidnumber 5555551212
nojitterbuffer

#Install Hylafax
apt -y install libtiff-tools libtiff5-dev ghostscript mgetty-voice netpbm imagemagick ubuntu-restricted-extras

cd /usr/src
tar zxf ghostscript-fonts-std-8.11.tar.gz -C /usr/share/ghostscript --no-same-owner

tar zxf hylafax-7.0.7.tar.gz
cd hylafax-7.0.7
./configure

make && make install
ln -s /usr/bin/gs /usr/local/bin/gs
faxsetup

nano /etc/ImageMagick-6/policy.xml

#Change Policies

nano /var/spool/hylafax/etc/config.ttyIAX1

CountryCode: 1
AreaCode: 555
FAXNumber: 555.555.1212
LongDistancePrefix: 1
InternationalPrefix: 011
DialStringRules: “etc/dialrules”
ServerTracing: 1
SessionTracing: 1
RecvFileMode: 0600
LogFileMode: 0600
DeviceMode: 0600
RingsBeforeAnswer: 1
SpeakerVolume: off
GettyArgs: “-h %l dx_%s”
LocalIdentifier: “15555551212”
TagLineFont: etc/lutRS18.pcf
TagLineFormat: “From %%l|%c|Page %%P of %%T”
MaxRecvPages: 200
JobReqNoCarrier: 180
JobReqNoAnswer: 180
FaxRcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
NotifyCmd: bin/notify.php
ModemType: Class1 # use this to supply a hint
ModemResetCmds: “ATH1\nAT+VCID=1” # enables CallID display
ModemReadyCmds: ATH0
Class1AdaptRecvCmd: AT+FAR=1
Class1TMConnectDelay: 400 # counteract quick CONNECT response
Class1RMQueryCmd: “!24,48,72,96” # V.17 fast-train recv doesn’t work well
Class1TMQueryCmd: “!24,48,72,96” # V.17 fast-train recv doesn’t work well
CallIDPattern: “NMBR=”
CallIDPattern: “NAME=”
CallIDPattern: “ANID=”
CallIDPattern: “NDID=”

cd /var/spool/hylafax/etc
chown uucp:uucp config.ttyIAX1

#Edit HylaFAX Verticle Resolution
nano /usr/local/lib/fax/hyla.conf

JobFmt: “%-5j %1a %15o %-15.15e %5P %5D %5i %7z %.25s”
RcvFmt: “%7o %-10t %-25s %-20f %5p %1z %-40e”
PageSize: na-let
VRes: 196

faxadduser -a admin
faxdeluser localhost
faxdeluser 127.0.0.1
echo 127.0.0.1 >> /var/spool/hylafax/etc/hosts.hfaxd

nano /etc/systemd/system/faxgetty1.service

[Unit]
Description=HylaFAX faxgetty for ttyIAX1

[Service]
User=root
Group=root
Restart=always
RestartSec=30
ExecStart=/usr/local/sbin/faxgetty ttyIAX1 &

[Install]
WantedBy=multi-user.target

nano /etc/systemd/system/iaxmodem1.service

[Unit]
Description=IAXModem for ttyIAX1

[Service]
Type = simple
Restart=always
RestartSec=30
ExecStart=/usr/local/sbin/iaxmodem ttyIAX1

[Install]
WantedBy=multi-user.target

nano /etc/systemd/system/hfaxd.service

[Unit]
Description=Hylafax hfaxd

[Service]
Type=forking
ExecStart=/usr/local/sbin/hfaxd -i hylafax

[Install]
WantedBy=multi-user.target

nano /etc/systemd/system/faxq.service

[Unit]
Description=faxq

[Service]
Type=forking
ExecStart=/usr/local/sbin/faxq

[Install]
WantedBy=multi-user.target

systemctl enable hfaxd.service
systemctl enable faxq.service
systemctl enable iaxmodem1.service
systemctl enable faxgetty1.service

systemctl start hfaxd.service
systemctl start faxq.service

systemctl start faxgetty1.service
systemctl start iaxmodem1.service

#If using Proxmox for wireguard to work set these settings
#LXC Container
features: mknod=1,nesting=1
lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file

#Install AvantFAX
cd /usr/src
tar zxf avantfax-3.4.0.tgz
cd avantfax-3.4.0
chown -R asterisk:asterisk *
cd avantfax
ln -s /usr/src/avantfax-3.4.0/avantfax /var/www/html/fax
chmod -R 770 /var/www/html/fax/tmp /var/www/html/fax/faxes
chmod -R 775 /var/www/html/fax/includes
chown -R asterisk:uucp /var/www/html/fax/tmp /var/www/html/fax/faxes
chown -R asterisk. /var/www/html/fax
chown -R asterisk. /var/run/asterisk
chown -R asterisk. /var/lib/asterisk
chown -R asterisk. /var/lib/php/sessions
chown -R asterisk. /var/spool/asterisk/*
chown -R asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib64/asterisk
chown -R asterisk. /var/www/html
chown -R asterisk. /run/php/
systemctl restart php7.4-fpm

mv /usr/local/bin/faxcover /usr/local/bin/faxcover.old
ln -s /var/www/html/fax/includes/faxcover.php /usr/local/bin/faxcover
ln -s /var/www/html/fax/includes/faxrcvd.php /var/spool/hylafax/bin/faxrcvd.php
ln -s /var/www/html/fax/includes/dynconf.php /var/spool/hylafax/bin/dynconf.php
ln -s /var/www/html/fax/includes/notify.php /var/spool/hylafax/bin/notify.php
ln -s /usr/local/bin/faxstat /usr/bin/faxstat

pear channel-update pear.php.net
pear install --alldeps Mail Net_SMTP Mail_mime MDB2_driver_mysql-beta pear/Auth_SASL2-beta pear/MDB2-beta pear/MDB2_Driver_mysqli-beta
pear channel-update pear.php.net
pear upgrade MDB2-beta
pear upgrade --force MDB2-beta#mysqli
cd …
mysql -p < create_user.sql

mysql -p avantfax < create_tables.sql

nano /etc/cron.d/avantfax

runs once an hour to update the phone book

0 * * * * /var/www/html/fax/includes/phb.php

runs once a day to remove old files

0 0 * * * /var/www/html/fax/includes/avantfaxcron.php -t 2

cp /var/www/html/fax/includes/local_config-example.php /var/www/html/fax/includes/local_config.php

#Edit local_config.php

nano /var/www/html/fax/includes/local_config.php

    $BINARYDIR                      = '/usr/bin';
    $HYLAFAX_PREFIX      		= '/usr/local';
    $HYLASPOOL                      = '/var/spool/hylafax';

define(‘OCR_BINARY’, “/usr/local/bin/tesseract”);
define(‘BARDECODE_BINARY’, “/usr/bin/bardecode”);

$HTML2PS = ‘/usr/bin/html2ps’; // path to html2ps

#Setup Sudoers
visudo

asterisk ALL = NOPASSWD: /sbin/reboot, /sbin/halt, /usr/local/sbin/faxdeluser, /usr/local/sbin/faxadduser -u * -p * *

#TO FORCE FAX IMPORT

cd /var/spool/hylafax; for i in ls recvq/*; do bin/faxrcvd.php $i ttyIAX1; done

#Avantfax Fix
cd /usr/src
mv mysqli.php /usr/share/php/MDB2/Driver/

tee /etc/mysql/conf.d/mysql.cnf<<EOF
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
EOF

systemctl restart mariadb
systemctl restart hylafax

#Canon Fax Test
855-392-2666

4 Likes

Thanks for sharing the product of your hard work. I will give it a whirl.

No problem thanks for trying it out. Getting everything to work was the key!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.