Telephony
PBX, SIP, GSM trunks
Asterisk and FreePBX on Debian12
Preparations
Database
Create new user in Cloud SQL
https://console.cloud.google.com/sql/instances/xxx/users?project=yyy
Warning: - dashes (hyphens) can not be used in the MariaDB databases' naming. To match user to database, only underlines are used.
Verify connection from the host to database server
mysql -h 172.21.32.6 -u pbx_2dz_fi_asterisk -p
Create database and grante permissions for Asterisk
CREATE DATABASE pbx_2dz_fi_asterisk CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE pbx_2dz_fi_asteriskcdrdb CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON pbx_2dz_fi_asterisk.* TO 'pbx_2dz_fi_asterisk'@'10.166.0.2';
GRANT ALL PRIVILEGES ON pbx_2dz_fi_asteriskcdrdb.* TO 'pbx_2dz_fi_asterisk'@'10.166.0.2';
FLUSH PRIVILEGES;
PHP installation
Elevate
sudo su
Install PHP and depending libraries
apt install \
php \
php-cli \
php-mysql \
php-gd \
php-curl \
php-mbstring \
php-xml \
php-bcmath \
php-zip \
php-json \
php-pear
Add more memory for PHP process
vi /etc/php/8.2/fpm/php.ini
# memory_limit = 128M
memory_limit = 256M
systemctl | grep php
systemctl restart php8.2-fpm
node.js installation
export dir="/home/anton/delme"
mkdir -p ${dir}
cd ${dir}
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
apt install nodejs
Asterisk installation
Choosing Asterisk version considerations
Pickup LTS version from Versions page. On the moment of writing (2025-10-08), it is v22.
https://docs.asterisk.org/About-the-Project/Asterisk-Versions/
Observer releases From official Github page
https://github.com/asterisk/asterisk/releases
https://github.com/asterisk/asterisk/releases/tag/22.5.2
Download Asterisk
export dir="/home/anton/delme"
mkdir -p ${dir}
cd ${dir}
export v="22.5.2"
curl -O -L https://github.com/asterisk/asterisk/releases/download/${v}/asterisk-${v}.tar.gz
curl -O -L https://github.com/asterisk/asterisk/releases/download/${v}/asterisk-${v}.sha256
sha256sum asterisk-${v}.tar.gz
cat asterisk-${v}.sha256
Unpack after checksum verification (comparison)
tar -xzvf asterisk-${v}.tar.gz
Change dir and install prerequisites
cd asterisk-${v}
contrib/scripts/install_prereq install
Configure
./configure
Define additional features
make menuselect
Enable mp3 support:
+ format_mp3
+ app_macro
Download additional libraries
contrib/scripts/get_mp3_source.sh
Build and install
make -j$(nproc)
[13:15:10 Sat Jun 20] @gcp1mx1 /home/anton/delme/asterisk-22.5.2# make -j$(nproc)
# usually, take time (took 35 min on 2-core GCP micro VM).
[13:49:33 Sat Jun 20] @gcp1mx1 /home/anton/delme/asterisk-22.5.2#
```bash
make install
make samples
make basic-pbx
make config
ldconfig
Create run directory
namei -mo /var/run/asterisk
mkdir -p /var/run/asterisk
Set permissions
?? # useradd -m asterisk
?? chown -R www-data:www-data \
/var/lib/asterisk \
/var/spool/asterisk \
/var/log/asterisk \
/var/run/asterisk \
/usr/lib/asterisk \
/var/lib/php/sessions \
Copy default config
mkdir -p /etc/asterisk/
cp /home/anton/delme/asterisk-22.5.2/configs/samples/asterisk.conf.sample /etc/asterisk/asterisk.conf
Modify config
vi /etc/asterisk/asterisk.conf
[directories]
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astdbdir => /var/lib/asterisk
astkeydir => /var/lib/asterisk
astdatadir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /var/log/asterisk
[options]
runuser = asterisk ; The user to run as.
rungroup = asterisk ; The group to run as.
Create service override
mkdir -p /etc/systemd/system/asterisk.service.d/
?? vi /etc/systemd/system/asterisk.service.d/override.conf
[Service]
User=asterisk
Group=asterisk
Enable and start the services
systemctl daemon-reexec
systemctl enable asterisk
systemctl restart asterisk
systemctl status asterisk
Verify
ps aux | grep asterisk
ss -ntap | grep asterisk
Define cert in config
TODO: update cert in Asterisk
FreePBX installation
Preparations, ensure that /var/www/html is empty and not used by any other applications/resources. Destination directory is hardcorded to the installation script and can not be changed. Once installation will be successful, it can be renamed. And it is better not to share that with any other applications.
ls -la /var/www/html/
Install preresequitives
apt install \
composer \
unzip
Check compatible version
https://github.com/FreePBX/framework/tags
Download FreePBX
export dir="/home/anton/delme"
mkdir -p ${dir}
cd ${dir}
git clone -b release/17.0 https://github.com/FreePBX/framework.git freepbx
cd freepbx
Initial FreePBX config
Install FreePBX
rm -rf /etc/freepbx.conf
rm -rf /etc/amportal.conf
./start_asterisk start
./install
vi /etc/freepbx.conf
adjust path
require_once('/var/www/pbx.2dz.fi/admin/bootstrap.php');
enable repo
fwconsole ma enablerepo standard
before
fwconsole ma listonline
List available online
fwconsole ma listonline
Install core module
fwconsole ma downloadinstall core
Enable core module
Update framework
fwconsole ma downloadinstall framework
Check that application installed
ls -la /var/www/html/admin
fgrep -irn freepbx.conf /var/www/html/admin/config.php
Move freshly installed directory
mv /var/www/html /var/www/pbx.2dz.fi
Enable host on Nginx webserver
cd /etc/nginx/sites-available
cp default pbx.2dz.fi.conf
ln -s /etc/nginx/sites-available/pbx.2dz.fi.conf /etc/nginx/sites-enabled/
Modify virtual host file to point to
vi /etc/nginx/sites-available/pbx.2dz.fi.conf
# root /var/www/html
root /var/www/pbx.2dz.fi
Test config and reload webserver
nginx -t
nginx -s reload
Check DNS record is published and match current machine
curl https://myip.2dz.fi
dig A pbx.2dz.fi +short
Request cert from LE (this will create additional SSL block in virtual server config)
certbot --nginx -d pbx.2dz.fi
Permissions fix
Here it becomes complicated.
Verify that utility can see variables:
fwconsole setting AMPASTERISKUSER
fwconsole setting AMPASTERISKGROUP
fwconsole setting AMPASTERISKWEBUSER
fwconsole setting AMPASTERISKWEBGROUP
fwconsole chwon
#? chown -R asterisk:asterisk /var/www/pbx.2dz.fi
chown -R www-data:www-data /var/www/pbx.2dz.fi
chown -R www-data:www-data /var/lib/php/sessions/
Change FreePBX log's group to www-data, for webserver user to write into
chown asterisk:www-data /var/log/asterisk/freepbx.log
Define database credentials created in the beginning
vi /etc/freepbx.conf
Welcome page
Login page
No nodules found
SIP configuration
Specify repos;
#?
Install modules
sudo su
fwconsole ma downloadinstall sipsettings
Upgrade:
fwconsole backup --list
fwconsole ma refreshsignatures
fwconsole ma upgradeall
fwconsole backup --list
fwconsole ma refreshsignatures
fwconsole ma listonline
fwconsole ma upgrade framework
fwconsole chown
fwconsole reload --verbose
Install Voicemail module
sudo -i
fwconsole ma refreshsignatures
rm -f /var/www/html/admin/modules/_cache/pm2*
fwconsole ma downloadinstall pm2
fwconsole ma enable pm2
fwconsole ma upgrade pm2
fwconsole chown
fwconsole ma refreshsignatures
fwconsole ma downloadinstall voicemail
fwconsole ma upgrade voicemail
fwconsole ma enable voicemail
fwconsole reload --verbose
fwconsole chown
change webuser in db
Default user comes NOT from config files, but from DATABASE !
Also local path to web directory is defined in database:
Enable 'cdr', 'sub-record-check' is normally generated by FreePBX call recording / core dialplan
It is necessary manually update CDR DB config in the main DB:
and config file
vi /etc/freepbx.conf
$amp_conf['CDRDBHOST'] = '172.00.00.00';
$amp_conf['CDRDBNAME'] = 'pbx_2dz_fi_asteriskcdrdb';
$amp_conf['CDRDBPASS'] = 'xxxxxxx';
$amp_conf['CDRDBPORT'] = '3306';
$amp_conf['CDRDBTABLENAME'] = 'cdr';
$amp_conf['CDRDBTYPE'] = 'mysql';
$amp_conf['CDRDBUSER'] = 'pbx_2dz_fi_asterisk';
$amp_conf['CDRUSEGMT'] = 0;
fwconsole ma downloadinstall cdr
fwconsole ma install cdr
Recordings:
fwconsole ma downloadinstall recordings
fwconsole ma downloadinstall callrecording
fwconsole ma enable \
recordings \
callrecording
fwconsole reload
Troubleshooting logs and tools:
fwconsole reload --verbose
# in new tmux pane
tail -f /var/log/asterisk/freepbx.log
# clean cache
ls -la /var/www/html/admin/modules/_cache/
Codecs on SIP phones
| Yealink T31P | Grandstream GRP-2602P | Cisco SPA-303 | Linphone | |
| Versions | FW 124.86.0.40 HW 123.1.1.0.2.0.0 |
|
Software Version: 7.4.9c
Hardware Version: 1.0.1 |
Android 9+: v6.2.3 (7 Jul 2026) |
| in order of priority |
Opus G722 PCMA PCMU
legacy:
G729AB G729 G726/40 kbps G726/32 kbps G726/24 kbps G726/16 kbps iLBC/15.2 kbps iLBC/13.3 kbps G723.1/63 kbps G723.1/53 kbps
|
Opus G722 PCMA PCMU
legacy:
G.729A/B
G.726-40 kbps G.726-32 kbps G.726-24 kbps G.726-16 kbps iLBC
G.723.1 kbps |
G722 G729a G711u G711a
legacy:
G726-40 G726-32 G726-24 G726-16
|
Opus/48 kHz Speex/16 kHz PCMU/8 kHz PCMA/8 kHz GSM/8 kHz G722/8 kHz iLBC/8 kHz G729/8 kHz iSAC/16 kHz speex/32kHz BV16/8 kHz L16/44.1 kHz
(priority order can not be defined in the UI)
! not supported: G.726 (legacy) G.723 (legacy) |