(Unofficial) FreePBX on Pi

So, I know bash scripts aren’t allowed here so what i post is not one but with a simple modification it might help those who boldly go (this works on DO/Buster)

#!/bin/nofuckingwayits a scriptforbash, if i was it would just be #!bin/bash, but it's not ;-)
# stage 1 setup base environment for DO, maybe others
#make as swap file for the needy
dd if=/dev/zero of=/.swapfile bs=1M count=1000
chmod 600 /.swapfile
mkswap /.swapfile
echo -e "/.swapfile\tswap\tswap" >> /etc/fstab
swapon -a

# get apt ready to apt
apt-get -y update
apt-get -y upgrade

# get php7.0 ready
apt install -y software-properties-common ca-certificates apt-transport-https curl gnupg2
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ buster main" > /etc/apt/sources.list.d/php.list

# install node/npm , (don't use 10+)
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt-get install -y nodejs

#fix the Cementos/Debian libicu  thingy
echo 'icuinfo 2>/dev/null|grep "\"version\""|sed "s/.*\">\(.*\)<.*/\1/g"' >  /usr/bin/icu-config
chmod +x  /usr/bin/icu-config

#stage 2 install the needed debs
apt-get install -y mlocate asterisk apache2 libapache2-mod-fcgid build-essential openssh-server apache2 mariadb-server \
mariadb-client bison flex php7.0 php7.0-curl php7.0-cli php7.0-pdo php7.0-mysql php7.0-mbstring php7.0-xml \
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 sudo subversion libtool-bin \
python-dev unixodbc dirmngr postfix  sudo  mc traceroute rsync sngrep ffmpeg

#set a reduced security for defult freepbx keys
sed -i  's/^CipherString.*/CipherString = DEFAULT@SECLEVEL=1/' /etc/ssl/openssl.cnf

#stage 3 install FreePBX
systemctl stop asterisk
rm -rf /etc/asterisk
mkdir /etc/asterisk
touch /etc/asterisk/{modules,cdr}.conf
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib/asterisk
rm -rf /var/www/html
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php/7.0/apache2/php.ini
cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
sed -i 's/^memory_limit.*$/memory_limit = 256M/g' /etc/php/7.0/apache2/php.ini
a2enmod rewrite
service apache2 restart
cd /usr/src
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-15.0-latest.tgz
tar vxfz freepbx-15.0-latest.tgz
rm -f freepbx-15.0-latest.tgz
cd freepbx
./start_asterisk start
./install -n

#last stage get, the basic modules  working for UCP
fwconsole ma upgradeall
fwconsole ma downloadinstall certman
fwconsole ma downloadinstall userman
fwconsole ma downloadinstall ucp
#fix notifications so oly the good guys remain
mysql asterisk -e 'delete from notifications'
fwconsole r

#should be ready go . . .

exit 0

Currently, there is a problem with pm2 on restaring the machine, I fix it with

fwconsole downloadinstall  ucp, 

a while after boot ( do the proper systemd enable rc-local thing )

wbrtc is dependent on ucp so include that disable/enable around the downloadinstall

(Thanks to all the behind the scenes dudes who got me going on this)

Rather than reinventing the wheel, there’s a fully automated script that’s been available for years:

https://www.dslreports.com/forum/r30661088-PBX-FreePBX-for-the-Raspberry-Pi

The included script (install) and archive (install.tar.gz) will build
FreePBX 13, 14, or 15 plus Asterisk 13, 15, 16, or 16-GVSIP on a Raspberry Pi.
iptables, dnsmasq, and exim4 are also installed.

Installation takes a approximately 35 minutes to complete on a Raspberry Pi 4B.

1 Like

If that’s Ron’s script, that compiles asterisk. That’s a terrible idea because then you don’t have all the QA resources of the distro you’re using managing security updates.

Now, some people may WANT to compile their own asterisk, and they may have some odd reason to do so, but 99% of people don’t (even if they think they do!)

The script I posted takes about 2 or 3 minutes to run, depending on your network speed.

3 Likes

100% this.

Hi Rob
nice job

will this work on the new Pi 64bit
or do you have to make some change to the script

Moz

6 posts were split to a new topic: High Availability (Split from another thread)

So , if you want CDR’s then you are as yet SOL , an effective libmaodbc.so is for me elusive on Buster, even if compiled from source, I imagine it is also not working on any hardware platform.

Otherwise everything else works peachy.

Comments please

For amd64 architecture (you said you were building on DigitalOcean), these packages work fine as referenced in the wiki: https://wiki.freepbx.org/display/FOP/Installing+FreePBX+15+on+Debian+9.6#InstallingFreePBX15onDebian9.6-InstallMariaDBODBC

And the “adaptive odbc cdr/cel” /libicu (UCP) also ?

what does “fwconsole pm2 --list” issue?

Are the the cdr/cel tables being populated?

But to answer, Yes, on Stretch it all works with php5.6 or php7.0, On Debian 10 (either amd64 or arm) not so much. None will be happy with php7.+ not even Stretch

Wasn’t this whole thing started of with attempting FreePBX 15 on Buster on a Pi4 (or any cpu for that matter) ?

This is where I will wait for mariadb to catch up. . .

I’m referring specifically to the packages for Maria-ODBC. The rest of that wiki is for Stretch, though it is mostly correct for Buster also. Yes, with those packages on Debian 10, I have working odbc / cdr / cel.

Excellent!, Where did you get your mariadb odbc connector (libmaodbc.so) from? 3.1.1 nor 3.1.2 doesn’t work in Debian10 for me, neither on a DO x86 or a PI4. I must be missing something

No tricks, I just used the ones listed there in the wiki.

Install MariaDB ODBC
cd /usr/src/
wget Sangoma Documentation
wget Sangoma Documentation
dpkg -i mariadb-connector-client-library_3.0.8-1_amd64.deb
dpkg -i mariadb-connector-odbc_3.0.7-1_amd64.deb

When installing the second package I had to add --force-overwrite because the first package already populates some common config files.

I will add that to my recipe, thanks!. And that will also work on a PI? Also the UCP?

You’ll need to compile from source for the Raspberry Pi:

  # Install MariaDB ODBC Connector
  cd /usr/src
  git clone https://github.com/MariaDB/mariadb-connector-odbc.git
  cd mariadb-connector-odbc
  git checkout tags/3.1.1-ga
  mkdir build
  cd build
  cmake ../ -LH -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_SSL=OPENSSL\
 -DDM_DIR=/usr/lib/arm-linux-gnueabihf -DCMAKE_C_FLAGS_RELEASE:STRING="-w"
  cmake --build . --config Release
  make install

  # Configure ODBC
  cat <<EOF > /etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL (MariaDB)
Driver = /usr/local/lib/libmaodbc.so
FileUsage = 1
EOF

  cat <<EOF > /etc/odbc.ini
[MySQL-asteriskcdrdb]
Description = MySQL connection to 'asteriskcdrdb' database
Driver = MySQL
Server = localhost
Database = asteriskcdrdb
Port = 3306
Socket = /var/run/mysqld/mysqld.sock
Option = 3
EOF

CDR/CEL/UCP all work.

In fact, everything works on both Stretch and Buster, FreePBX 14 and 15, using:

https://www.dslreports.com/forum/r30661088-PBX-FreePBX-for-the-Raspberry-Pi

2 Likes

Excellent, already had the compile from source thing, followed your /etc/odbc*.ini setup, which I had effed up and now my script is slick as a soacs, Thanks so much

fwconsole ma list
No repos specified, using: [standard] from last GUI settings

+---------------------+-----------+---------+---------+
| Module              | Version   | Status  | License |
+---------------------+-----------+---------+---------+
| accountcodepreserve | 13.0.2.2  | Enabled | GPLv2   |
| amd                 | 15.0.2    | Enabled | GPLv3+  |
| announcement        | 15.0.3.6  | Enabled | GPLv3+  |
| api                 | 15.0.3.2  | Enabled | AGPLv3+ |
| arimanager          | 15.0.3.3  | Enabled | GPLv3+  |
| asteriskinfo        | 15.0.4.1  | Enabled | GPLv3+  |
| backup              | 15.0.8.17 | Enabled | GPLv3+  |
| blacklist           | 15.0.2.6  | Enabled | GPLv3+  |
| builtin             |           | Enabled |         |
| bulkhandler         | 13.0.14.8 | Enabled | GPLv3+  |
| calendar            | 15.0.4.6  | Enabled | GPLv3+  |
| callback            | 15.0.5    | Enabled | GPLv3+  |
| callforward         | 15.0.8    | Enabled | AGPLv3+ |
| callrecording       | 15.0.7.8  | Enabled | AGPLv3+ |
| callwaiting         | 15.0.4.1  | Enabled | GPLv3+  |
| campon              | 13.0.4.1  | Enabled | GPLv3+  |
| cdr                 | 15.0.11   | Enabled | GPLv3+  |
| cel                 | 15.0.11   | Enabled | GPLv3+  |
| certman             | 15.0.10   | Enabled | AGPLv3+ |
| cidlookup           | 15.0.7    | Enabled | GPLv3+  |
| conferences         | 15.0.6.5  | Enabled | GPLv3+  |
| contactmanager      | 15.0.8.9  | Enabled | GPLv3+  |
| core                | 15.0.9.28 | Enabled | GPLv3+  |
| customappsreg       | 15.0.11   | Enabled | GPLv3+  |
| customcontexts      | 13.0.3.1  | Enabled | GPLv2+  |
| dashboard           | 15.0.1.1  | Enabled | AGPLv3+ |
| daynight            | 15.0.7    | Enabled | GPLv3+  |
| dictate             | 15.0.4    | Enabled | GPLv3+  |
| directory           | 15.0.12   | Enabled | GPLv3+  |
| disa                | 15.0.4.6  | Enabled | AGPLv3+ |
| donotdisturb        | 15.0.5    | Enabled | GPLv3+  |
| extensionsettings   | 13.0.4    | Enabled | GPLv3+  |
| fax                 | 15.0.13   | Enabled | GPLv3+  |
| featurecodeadmin    | 13.0.6.4  | Enabled | GPLv3+  |
| filestore           | 15.0.3    | Enabled | AGPLv3  |
| findmefollow        | 15.0.13   | Enabled | GPLv3+  |
| framework           | 15.0.16   | Enabled | GPLv2+  |
| fw_langpacks        | 14.0.1    | Enabled | GPLv3+  |
| hotelwakeup         | 15.0.5.1  | Enabled | GPLv2   |
| iaxsettings         | 15.0.5    | Enabled | AGPLv3  |
| infoservices        | 15.0.2    | Enabled | GPLv2+  |
| irc                 | 13.0.1    | Enabled | GPLv3+  |
| ivr                 | 15.0.14   | Enabled | GPLv3+  |
| languages           | 15.0.6    | Enabled | GPLv3+  |
| logfiles            | 13.0.10.5 | Enabled | GPLv3+  |
| manager             | 15.0.5    | Enabled | GPLv2+  |
| miscapps            | 15.0.4    | Enabled | GPLv3+  |
| miscdests           | 15.0.2.5  | Enabled | GPLv3+  |
| music               | 15.0.11   | Enabled | GPLv3+  |
| outroutemsg         | 15.0.7    | Enabled | GPLv3+  |
| paging              | 15.0.4.10 | Enabled | GPLv3+  |
| parking             | 15.0.9    | Enabled | GPLv3+  |
| pbdirectory         | 2.11.0.6  | Enabled | GPLv3+  |
| phonebook           | 15.0.7    | Enabled | GPLv3+  |
| pinsets             | 15.0.1.6  | Enabled | GPLv3+  |
| pm2                 | 15.0.3.6  | Enabled | AGPLv3+ |
| presencestate       | 15.0.5    | Enabled | GPLv3+  |
| printextensions     | 13.0.3.2  | Enabled | GPLv3+  |
| queueprio           | 15.0.5    | Enabled | GPLv3+  |
| queues              | 15.0.9    | Enabled | GPLv2+  |
| recordings          | 15.0.3.4  | Enabled | GPLv3+  |
| ringgroups          | 15.0.11   | Enabled | GPLv3+  |
| setcid              | 15.0.4    | Enabled | GPLv3+  |
| sipsettings         | 15.0.6.7  | Enabled | AGPLv3+ |
| soundlang           | 15.0.4.1  | Enabled | GPLv3+  |
| speeddial           | 2.11.0.4  | Enabled | GPLv3+  |
| superfecta          | 15.0.2.13 | Enabled | GPLv2+  |
| timeconditions      | 15.0.12   | Enabled | GPLv3+  |
| ttsengines          | 15.0.4.3  | Enabled | AGPLv3  |
| ucp                 | 15.0.6.3  | Enabled | AGPLv3+ |
| userman             | 15.0.8.2  | Enabled | AGPLv3+ |
| vmblast             | 15.0.11   | Enabled | GPLv3+  |
| voicemail           | 15.0.17.5 | Enabled | GPLv3+  |
| weakpasswords       | 13.0.2    | Enabled | GPLv3+  |
| webrtc              | 15.0.5    | Enabled | GPLv3+  |
+---------------------+-----------+---------+---------+

root@deb10-latest:~# fwconsole pm2 --list
+--------------+-------+--------+----------+----------------------+-----+---------+
| Process Name | PID   | Status | Restarts | Uptime               | CPU | Mem     |
+--------------+-------+--------+----------+----------------------+-----+---------+
| core-fastagi | 17992 | online | 0        | 9 minutes, 7 seconds | 0%  | 35.38MB |
| ucp          | 18091 | online | 0        | 9 minutes, 5 seconds | 0%  | 49.97MB |
+--------------+-------+--------+----------+----------------------+-----+---------+

root@deb10-latest:~# uname -a
Linux deb10-latest 4.19.0-5-cloud-amd64 #1 SMP Debian 4.19.37-5 (2019-06-19) x86_64 GNU/Linux

fwconsole -V
FW Console - FreePBX Utility 15.0.16

rasterisk -V
Asterisk 16.2.1~dfsg-1

took 8 minutes on a DO droplet, Now to do the same script on a Pi4

One of the reasons I prefer compiling Asterisk instead of using a package is I get the the latest release and don’t have to wait several months for it to be packaged:

rasterisk -V
Asterisk 16.4.1

And I totally agree, but that is easily script-able, but you have to wait several minutes for it to be installed, ( I can wait 8 minutes, 25 minutes kicks my add in :wink: ) and so far this is just a POC (that looks solid) ,

Thus I prefer the “asterisk latest” as a separate process to do that, as a point of note on Buster you get asterisk 16 dot a while ago , but on Stretch it is a very long while ago. I wonder who is the “Debian VoIP Team”

Couple of notes for scripts that “swings both ways”

I think libsrtp?-dev is as yet platform dependent and as yet

icu-config

needs to work on debian for UCP to be installable

I recently started using libsrtp2-dev (on RPi) and the last I checked, nothing complained on either Stretch or Buster. I don’t do any SRTP, however, so I’m assuming it’s working.

ucp v14.0.3.6 and ucp v15.0.6.6 (both EDGE modules) now use pkg-config instead of libicu-dev to determine the underlying OS, allowing UCP to install and run on both Stretch and Buster.

1 Like

Both points noted, thanks! Pi4 is crunching . .

The 35 minutes on an RPi includes updating Raspbian, updating FreePBX modules to EDGE versions (optional, but pretty much required on FreePBX 15), installing additional sounds, installing iptables, exim4, and dnsmasq, and a number customizations. When the script finishes, everything is up to date and ready to go.