Installing FreePBX 13 on Centos 7, On Google Compute Engine

Most of the contents of this page are from freepbx's official site, during install I noticed some things didnt jive with my system.

Just create a machine, asterisk doesn't need much hardware-wise. We use a single core, with a 1GB of RAM for well over 100,000 minutes a month.

GCloud machine build script

# gcloud beta compute --project "virtual-cluster" instances create "freepbx" --zone "us-central1-a" --machine-type "custom-1-2048" --network "default" --maintenance-policy "MIGRATE" --service-account "529948XXX-compute@developer.gserviceaccount.com" --scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring.write","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --min-cpu-platform "Automatic" --tags "http-server","https-server" --image "centos-7-v20170816" --image-project "centos-cloud" --boot-disk-size "40" --boot-disk-type "pd-standard" --boot-disk-device-name "instance-1"

and log in

# gcloud compute ssh <instancename> --project=projectname 

Now we run the following commands on your newly created instance.

1.) disable SELINUX.

# sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/sysconfig/selinux
# sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config

2.) Now we need to update the system and install development-tools

sudo yum -y update  
# yum -y groupinstall core base "Development Tools"

3.) Installing additional required dependancies.

# yum -y install lynx mariadb-server mariadb php php-mysql php-mbstring tftp-server httpd ncurses-devel sendmail sendmail-cf sox newt-devel libxml2-devel libtiff-devel audiofile-devel gtk2-devel subversion kernel-devel git php-process crontabs cronie cronie-anacron wget vim php-xml uuid-devel sqlite-devel net-tools gnutls-devel php-pear unixODBC mysql-connector-odbc

4.) Install legacy Pear requirements.

# pear install Console_Getopt

5.) Firewalld basic config.

# firewall-cmd --zone=public --add-port=80/tcp --permanent
# firewall-cmd --reload

6.) Mariadb setup.

# systemctl enable mariadb
# systemctl start mariadb

and secure mariadb server

# mysql_secure_installation

The prompt will ask you for your current root user password, since this is a new install just leave password blank when you secure.

7.) Enable and start Apache web server

# systemctl enable httpd
# systemctl start httpd

8.) Install dependancies for Google Voice (optional)

# cd /usr/src
# wget https://iksemel.googlecode.com/files/iksemel-1.4.tar.gz
# tar xf iksemel-*.tar.gz
# rm -f iksemel-1.4.tar.gz
# cd iksemel-*
# ./configure
# make
# make install

9.) Install and configure Asterisk

# cd /usr/src
# wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
# wget -O jansson.tar.gz https://github.com/akheron/jansson/archive/v2.7.tar.gz
# wget http://www.pjsip.org/release/2.4/pjproject-2.4.tar.bz2

10.) Install DAHDI (only required if you use PSTN hardware, T1, E1, etc.

# cd /usr/src
# tar xvfz dahdi-linux-complete-current.tar.gz
# tar xvfz libpri-current.tar.gz
# rm -f dahdi-linux-complete-current.tar.gz libpri-current.tar.gz
# cd dahdi-linux-complete-*
# make all
# make install
# make config
# cd /usr/src/libpri-*
# make
# make install

11.) Compile and install pjproject.

# cd /usr/src
# tar -xjvf pjproject-2.4.tar.bz2
# rm -f pjproject-2.4.tar.bz2
# cd pjproject-2.4
# CFLAGS='-DPJ_HAS_IPV6=1' ./configure --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr --libdir=/usr/lib64
# make dep
# make
# make install

12.) Compile and install jansson

# cd /usr/src
# tar vxfz jansson.tar.gz
# rm -f jansson.tar.gz
# cd jansson-*
# autoreconf -i
# ./configure --libdir=/usr/lib64
# make
# make install

Bug alert - Some versions of Asterisk will crash with a missing ari.conf https://issues.asterisk.org/jira/browse/ASTERISK-27026 You may wish to mkdir -p /etc/asterisk && touch /etc/asterisk/ari.conf after compiling Asterisk

13.) Compile and install asterisk.

# cd /usr/src
# tar xvfz asterisk-13-current.tar.gz
# rm -f asterisk-13-current.tar.gz
# cd asterisk-*
# contrib/scripts/install_prereq install
# ./configure --libdir=/usr/lib64
# contrib/scripts/get_mp3_source.sh
# make menuselect

make menuselect will display a window in the terminal, check format_mp3 to add mp3 playback and encoding.

One you save and exit the menuselect window, we need to install asterisk.

# make # this will take a while.
# make install
# make config
# ldconfig
# chkconfig asterisk off

Installing higher quality asterisk sound files.

# cd /var/lib/asterisk/sounds
# wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-en-wav-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-wav-current.tar.gz
# tar xvf asterisk-core-sounds-en-wav-current.tar.gz
# rm -f asterisk-core-sounds-en-wav-current.tar.gz
# tar xfz asterisk-extra-sounds-en-wav-current.tar.gz
# rm -f asterisk-extra-sounds-en-wav-current.tar.gz

###### Wideband Audio download
# wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-en-g722-current.tar.gz
# wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-g722-current.tar.gz
# tar xfz asterisk-extra-sounds-en-g722-current.tar.gz
# rm -f asterisk-extra-sounds-en-g722-current.tar.gz
# tar xfz asterisk-core-sounds-en-g722-current.tar.gz
# rm -f asterisk-core-sounds-en-g722-current.tar.gz

setting asterisk user permissions. I had to add an asterisk user at this point.

# useradd asterisk

# chown asterisk. /var/run/asterisk
# chown -R asterisk. /etc/asterisk
# chown -R asterisk. /var/{lib,log,spool}/asterisk
# chown -R asterisk. /usr/lib64/asterisk
# chown -R asterisk. /var/www/

14.) Apache modifications.

# sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php.ini
# sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/httpd/conf/httpd.conf
# sed -i 's/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
# systemctl restart httpd.service

Now we download and install freepbx.

note the final command (./install -n) needs --dbpass appended if you secured your installation in the previous steps. (./install -n --dbpass $password)

# cd /usr/src
# wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-13.0-latest.tgz
# tar xfz freepbx-13.0-latest.tgz
# rm -f freepbx-13.0-latest.tgz
# cd freepbx
# ./start_asterisk start
# ./install -n

Centos 7 systemd config, to autostart freePBX on boot.

create a file named freepbx.service in /etc/systemd/system containing the following text:

[Unit]
Description=FreePBX VoIP Server  
After=mariadb.service

[Service]
Type=oneshot  
RemainAfterExit=yes  
ExecStart=/usr/sbin/fwconsole start -q  
ExecStop=/usr/sbin/fwconsole stop -q

[Install]
WantedBy=multi-user.target  

then reload the daemons, so we can enable the service, if you tried to enable before reloading systemd wouldnt see your config changes.

# systemctl daemon reload
# systemctl enable freepbx

on reboot, following the above instructions, I needed to start asterisk. The below commands will fix it.

# systemctl enable asterisk
# reboot

Open some ports for SIP to be happy. These ports also need to be added to the compute engine firewall for the instance.

firewall-cmd --zone=public --add-port=5060-5061/tcp --permanent  
firewall-cmd --zone=public --add-port=5060-5061/udp --permanent  
firewall-cmd --zone=public --add-port=10000-20000/tcp --permanent  
firewall-cmd --zone=public --add-port=10000-20000/udp --permanent  
firewall-cmd --reload  

to add the firewall rules on Google Compute engine:

gcloud beta compute --project=virtual-cluster firewall-rules create asterisk --description=default\ phone\ system\ ports --direction=INGRESS --priority=1000 --network=default --allow=tcp:5060-5061,udp:5060-5061,tcp:10000-20000,udp:10000-20000 --source-ranges=0.0.0.0/0 --target-tags=asterisk

To add the rules to an instance, go to the instance in cloud.google.com, and add "asterisk" to network tags. Once added, save changes by scrolling down to bottom of page, and clicking save changes.