Installing-freepbx-and-asterisk-on-ubuntu-22-04-lts
Sumber : https://32n.co/blog/installing-freepbx-and-asterisk-on-ubuntu-22-04-lts/
This guide describes the installation of Asterisk and FreePBX on Ubuntu 22.04 LTS. The procedure includes system preparation, dependency installation, Asterisk compilation and configuration, PHP and web-server configuration, and installation of FreePBX.
A custom installation of FreePBX may differ from a pre-built FreePBX distribution. In particular, some modules or administrative components that are normally included or configured in a complete FreePBX distribution may not be present after a manual installation.
One such component is the Admin Module. The Admin Module provides a web-based interface for managing various aspects of a FreePBX system, including users, permissions, system settings, and module administration.
If the Admin Module is unavailable after a custom installation, it may need to be installed separately. Administrative operations can also be performed through the FreePBX command-line interface (CLI) or by modifying configuration files directly. Consequently, some functionality normally available through the FreePBX web interface may require additional configuration when FreePBX is installed manually.
Prerequisites
The procedure assumes the following:
· A fresh installation of Ubuntu 22.04 LTS.
· Root or sudo access to the server.
· Internet connectivity for downloading packages and source code.
· A server with sufficient resources to compile and run Asterisk and FreePBX.
Step 1: Update the system
The system should first be updated so that installed packages are current.
apt-get update -y
apt-get upgrade -y
Step 2: Set the hostname
Set the hostname of the server to freepbx:
hostnamectl set-hostname freepbx
nano /etc/hosts
Add the appropriate IP address, hostname, and DNS or domain name entries to /etc/hosts.
The exact entries depend on the network configuration of the server.
Step 3: Configure swap space
Swap space can be configured to provide additional virtual memory and help prevent memory exhaustion during software compilation and operation.
First, check the current swap, memory, and disk configuration:
sudo swapon --show
free -h
df -h
Create a 2 GB swap file:
sudo fallocate -l 2G /swapfile
ls -lh /swapfile
Set the appropriate permissions:
sudo chmod 600 /swapfile
ls -lh /swapfile
Initialize and enable the swap file:
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
free -h
Back up the existing /etc/fstab file:
sudo cp /etc/fstab /etc/fstab.bak
Add the swap file to /etc/fstab so that it is automatically enabled after a reboot:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
The Linux virtual-memory parameters can be adjusted in /etc/sysctl.conf:
sudo nano /etc/sysctl.conf
Add the following values:
vm.swappiness=10
vm.vfs_cache_pressure=50
The resulting configuration can be inspected with:
cat /etc/sysctl.conf
Step 4: Reboot the system
Reboot the server to apply the system configuration changes:
reboot
Step 5: Install Asterisk
Install the packages required to compile Asterisk and provide several of its optional components:
apt-get install unzip git sox gnupg2 curl libnewt-dev libssl-dev libncurses5-dev subversion libsqlite3-dev build-essential libjansson-dev libxml2-dev libedit-dev uuid-dev subversion -y
Download the current Asterisk 20 source archive:
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gz
Extract the archive:
tar -xvzf asterisk-20-current.tar.gz
Change to the extracted Asterisk source directory:
cd asterisk-20.*
Download the MP3 source required for MP3 support:
contrib/scripts/get_mp3_source.sh
Install the Asterisk prerequisite packages:
contrib/scripts/install_prereq install
Configure the Asterisk build:
./configure
Open the Asterisk module-selection interface:
make menuselect
Compile and install Asterisk:
make -j2
make install
make samples
make config
ldconfig
The -j2 option instructs make to use two parallel jobs during compilation. The number can be adjusted according to the available CPU resources.
Step 6: Configure Asterisk
A dedicated system user and group are used to run Asterisk.
Create the Asterisk group:
groupadd asterisk
Create the Asterisk system user:
useradd -r -d /var/lib/asterisk -g asterisk asterisk
Add the Asterisk user to the audio and dialout groups:
usermod -aG audio,dialout asterisk
Change ownership of the Asterisk configuration, library, log, and spool directories:
chown -R asterisk.asterisk /etc/asterisk
chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
chown -R asterisk.asterisk /usr/lib/asterisk
Edit the Asterisk default configuration:
nano /etc/default/asterisk
Set the following values:
AST_USER="asterisk"
AST_GROUP="asterisk"
The Asterisk configuration file can also be used to specify the user and group under which the Asterisk process operates:
nano /etc/asterisk/asterisk.conf
Set the following values:
runuser = asterisk
rungroup = asterisk
Restart Asterisk and enable it to start automatically with the system:
systemctl restart asterisk
systemctl enable asterisk
systemctl status asterisk
Correct common configuration errors
The following commands modify the Asterisk CDR and CEL configuration files to correct common RADIUS-related configuration issues:
sed -i 's";\[radius\]"\[radius\]"g' /etc/asterisk/cdr.conf
sed -i 's";radiuscfg => /usr/local/etc/radiusclient-ng/radiusclient.conf"radiuscfg => /etc/radcli/radiusclient.conf"g' /etc/asterisk/cdr.conf
sed -i 's";radiuscfg => /usr/local/etc/radiusclient-ng/radiusclient.conf"radiuscfg => /etc/radcli/radiusclient.conf"g' /etc/asterisk/cel.conf
Start Asterisk and connect to its command-line interface:
systemctl start asterisk
asterisk -rvv
After verifying the Asterisk CLI, leave it with:
exit
Step 7: Install FreePBX dependencies
FreePBX requires a web server, database server, PHP, and several PHP extensions.
Install software-properties-common:
apt install software-properties-common
Add the Ondřej Surý PHP repository:
add-apt-repository ppa:ondrej/php -y
Install Apache HTTP Server, MariaDB, PHP 7.4, and the required PHP extensions:
apt install apache2 mariadb-server libapache2-mod-php7.4 php7.4 php-pear php7.4-cgi php7.4-common php7.4-curl php7.4-mbstring php7.4-gd php7.4-mysql php7.4-bcmath php7.4-zip php7.4-xml php7.4-imap php7.4-json php7.4-snmp -y
Configure PHP 7.4 as the default PHP version
Disable the currently enabled Apache PHP modules:
sudo a2dismod php*
Enable the PHP 7.4 Apache module:
sudo a2enmod php7.4
Restart Apache:
sudo systemctl restart apache2
Set PHP 7.4 as the default command-line PHP version:
sudo update-alternatives --set php /usr/bin/php7.4
sudo update-alternatives --set phar /usr/bin/phar7.4
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4
sudo update-alternatives --set phpize /usr/bin/phpize7.4
sudo update-alternatives --set php-config /usr/bin/php-config7.4
Step 8: Download and install FreePBX
Download the latest FreePBX 16 release available from the specified FreePBX mirror:
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-16.0-latest.tgz
Extract the archive:
tar -xvzf freepbx-16.0-latest.tgz
Change to the FreePBX source directory:
cd freepbx
Install Node.js and npm:
apt-get install nodejs npm -y
Run the FreePBX installer:
./install -n
Install the FreePBX PM2 module:
fwconsole ma install pm2
Configure Apache
Set the Apache process to use the asterisk user and group:
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
Enable Apache directory overrides:
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
Enable Apache URL rewriting:
a2enmod rewrite
Restart Apache:
systemctl restart apache2
Step 9: Configure PHP
The PHP configuration can be adjusted to allow larger uploads and provide additional memory for PHP processes.
For the Apache PHP configuration, modify upload_max_filesize:
sed -i 's/\(^upload_max_filesize = \).*/\512M/' /etc/php/7.4/apache2/php.ini
Apply the same setting to the PHP CLI configuration:
sed -i 's/\(^upload_max_filesize = \).*/\512M/' /etc/php/7.4/cli/php.ini
Set the PHP memory limit for Apache:
sed -i 's/\(^memory_limit = \).*/\1512M/' /etc/php/7.4/apache2/php.ini
Set the PHP CLI memory limit:
sed -i 's/\(^memory_limit = \).*/\1512M/' /etc/php/7.4/cli/php.ini
Restart Apache to apply the PHP configuration:
systemctl restart apache2
Admin Module considerations
A manually compiled installation of Asterisk and a manually installed FreePBX system is different from a pre-built FreePBX distribution. Components that are automatically installed, configured, or maintained by a distribution may therefore require additional configuration.
If the FreePBX Admin Module is not displayed after installation, the installation should be checked using the FreePBX CLI:
fwconsole moduleadmin
The available modules can also be examined with:
fwconsole ma list
Module installation or activation can be performed through the FreePBX module management commands when the required module is available.
The FreePBX CLI can also be used to perform administrative operations when the corresponding web interface is unavailable.
Notes
This procedure describes a specific custom installation environment and should not be interpreted as a universal installation procedure for every version of FreePBX or Asterisk. Package names, PHP versions, dependencies, repository availability, and compatibility requirements may change between releases.
In particular, PHP 7.4 is an end-of-life PHP release. Its use should therefore be considered in the context of the specific FreePBX version and compatibility requirements for which this procedure was originally developed. For new deployments, the PHP version supported by the target FreePBX release should be verified before installation.
Likewise, the asterisk-20-current.tar.gz archive refers to the current Asterisk 20 source available from the specified download location at the time of installation. The resulting version may change as new Asterisk 20 rel