Skip to main content

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 asterisk:asteriskwww-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 listlistonline

List available online

fwconsole ma listonline

Install core module

fwconsole ma downloadinstall core

Enable core module


Update framework

fwconsole ma downloadinstall framework

after

Install FreePBX

rm -rf /etc/freepbx.conf
rm -rf /etc/amportal.conf

./start_asterisk start
./install 

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

TODO:vi move/etc/nginx/sites-available/pbx.2dz.fi.conf
to
# root /var/www/html
root /var/www/pbx.2dz.fi
    root /var/www/html/;

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 mkdirsetting -pAMPASTERISKUSER
/var/www/pbx.2dz.fifwconsole 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/
chown -R www-data:www-data /var/www/html/admin/
chown    www-data:www-data /etc/freepbx.conf

usermod -aG asterisk www-data
usermod -aG www-data asterisk

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

Initial page

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 chownma #?downloadinstall voicemail

fwconsole ma upgrade voicemail
fwconsole backupma --listenable 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:

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/