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

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)
make install
make samples
make basic-pbx
make config
ldconfig

Create run directory

mkdir -p /var/run/asterisk

Set permissions

useradd -m asterisk
chown -R asterisk:asterisk \
    /var/lib/asterisk \
    /var/spool/asterisk \
    /var/log/asterisk \
    /var/run/asterisk \
    /usr/lib/asterisk

Copy default config

cp /home/anton/delme/asterisk-22.5.2/configs/samples/asterisk.conf.sample /etc/asterisk/asterisk.conf

Modify config

vi /etc/asterisk/asterisk.conf
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

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

before

fwconsole ma list

List available online

fwconsole ma listonline

Install core module

fwconsole ma downloadinstall core

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

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: move to  /var/www/pbx.2dz.fi
    root /var/www/html/;

Test config and reload webserver

nginx -t
nginx -s reload

Request cert from LE (this will create additional SSL block in virtual server config)

certbot --nginx -d pbx.2dz.fi

Permissions fix

#? mkdir -p /var/www/pbx.2dz.fi
#? 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

No nodules found


Upgrade:

fwconsole ma listonline
fwconsole ma upgrade framework
fwconsole ma refreshsignatures
fwconsole chown
#? fwconsole backup --list
fwconsole reload