26 July 2021 Reading time: 9 minutes

Yuri Galeev

Tech Support

Virtual PBX as a service in the VMmanager platform

Virtual PBX as a service in the VMmanager platform



With VMmanager, hosting providers can offer not only a virtual machine with a preinstalled operating system, but also a SaaS service. It does not require the development of a custom solution. Freeware can be used instead. I will tell you about this solution with the example of a virtual PBX. Let us configure the service using VMmanager. We will need a PBX and a web interface to manage it.

The most popular free PBX is Asterisk
However, it has no visual interface, and most ordinary users should not be expected to understand the subtleties of managing it through the console. Therefore, we will install FreePBX to manage the virtual PBX. As a result, the script will provide two services: Asterisk and FreePBX.

How to create a script to install a PBX

Creating a script in VMmanager. Using this script, a PBX can be automatically installed on virtual machines with the Linux tag
Creating a script in VMmanager. Using this script, a PBX can be automatically installed on virtual machines with the Linux tag
  1. Enter Scripts → Create script.
  2. Specify the name of the script.
  3. Select the Owner of the script. Only the owner can edit the script.
  4. Select who is allowed to access the image:
    - owner;
    - all.
  5. If necessary, enable the Hide script contents option. Then only the owner of the script and platform administrators will be able to view the script code and create copies of it.
  6. Select tags to classify the script and its relationship to the OS. The script is available to run on the OS when at least one tag matches between them.
  7. Provide a brief description of the script. It appears in the list of scripts.
  8. Select the script type: Shell — for a Linus family OS;
  9. Enter the Script body in the editor window:
 export DEBIAN_FRONTEND="noninteractive"
 set -x
 mkfifo ${LOG_PIPE}
 touch ${LOG_FILE}
 chmod 600 ${LOG_FILE}
 tee < ${LOG_PIPE} ${LOG_FILE} &
 exec > ${LOG_PIPE}
 exec 2> ${LOG_PIPE}
 echo deb http://ftp.us.debian.org/debian/ buster-backports main > /etc/apt/sources.list.d/backports.list
 echo deb-src http://ftp.us.debian.org/debian/ buster-backports main >> /etc/apt/sources.list.d/backports.list
 apt-get update -y
 apt-get upgrade -y
 #Install all the necessary packages
 apt-get install -y build-essential openssh-server apache2 mariadb-server mariadb-client bison flex php php-curl php-cli php-pdo php-mysql php-pear php-gd php-mbstring php-intl php-bcmath curl sox libncurses5-dev libssl-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git unixodbc-dev uuid uuid-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libcurl4-openssl-dev libical-dev libneon27-dev libsrtp2-dev libspandsp-dev subversion libtool-bin python-dev unixodbc dirmngr sendmail-bin sendmail asterisk debhelper-compat cmake libmariadb-dev odbc-mariadb php-ldap
 #Install Node.js
 curl -sL https://deb.nodesource.com/setup_11.x | bash -
 apt-get install -y nodejs
 #Install this required Pear module
 pear install Console_Getopt
 #Prepare Asterisk
 systemctl stop asterisk
 systemctl disable asterisk
 mkdir /etc/asterisk/DIST
 mv /etc/asterisk/* /etc/asterisk/DIST
 cp /etc/asterisk/DIST/asterisk.conf /media/
 sed -i 's/(!)//' /etc/asterisk/DIST/asterisk.conf
 touch /etc/asterisk/modules.conf
 touch /etc/asterisk/cdr.conf
 #Configure Apache web server
 sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/7.3/apache2/php.ini
 sed -i 's/\(^memory_limit = \).*/\1256M/' /etc/php/7.3/apache2/php.ini
 sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
 sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
 systemctl restart apache2
 rm /var/www/html/index.html
 #Configure ODBC
 cat > /etc/odbcinst.ini << EOF
 Description = ODBC for MySQL (MariaDB)
 Driver = /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so
 FileUsage = 1
 cat > /etc/odbc.ini << EOF
 Description = MySQL connection to 'asteriskcdrdb' database
 Driver = MySQL
 Server = localhost
 Database = asteriskcdrdb
 Port = 3306
 Socket = /var/run/mysqld/mysqld.sock
 Option = 3
 #Download FFMPEG static build for sound file manipulation
 wget --directory-prefix=/usr/local/src https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
 tar -C /usr/local/src/ -xvf /usr/local/src/ffmpeg-release-amd64-static.tar.xz
 mv /usr/local/src/ffmpeg-4.4-amd64-static/ffmpeg /usr/local/bin
 #Install FreePBX
 cd /usr/local/src
 wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-15.0-latest.tgz
 tar zxvf freepbx-15.0-latest.tgz
 cd /usr/local/src/freepbx/
 ./start_asterisk start
 ./install -n
 fwconsole ma installall
 fwconsole reload
 cd /usr/share/asterisk
 mv sounds sounds-DIST
 ln -s /var/lib/asterisk/sounds sounds
 fwconsole restart
 cat >/etc/systemd/system/freepbx.service<< EOF
 Description=FreePBX VoIP Server
 ExecStart=/usr/sbin/fwconsole start -q
 ExecStop=/usr/sbin/fwconsole stop -q
 systemctl daemon-reload
 ps -aux | grep /usr/sbin/asterisk | grep -v grep| awk '{print $2}' | xargs kill
 systemctl enable asterisk.service
 systemctl start asterisk
 a2enmod rewrite
 service apache2 restart

After that, the interface of the virtual PBX will be available at http://YOUR-IP/admin/config.php
Follow this link to create the first user - and the virtual PBX is ready to use.

Using scripts in VMmanager, you can create not only PBX, but also deploy any other software on virtual machines to provide SaaS.

Other examples were shared by my colleagues:

Try VMmanager to manage your virtual infrastructure.

KVM-based virtual machines and LXD lightweight containers;

IaaS - isolated virtual infrastructure with private network management;

SaaS - provisioning of a VM with pre-installed and pre-configured software;

high availability - in the case of a failure, VMs are automatically restored to a serviceable node.