Installing-freepbx-and-asterisk-on-ubuntu-22-04-lts

From Dboswiki
Revision as of 17:03, 11 September 2026 by Smpdbos (talk | contribs) (Created page with " Sumber : https://32n.co/blog/installing-freepbx-and-asterisk-on-ubuntu-22-04-lts/ # FreePBX and Asterisk installation 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 FreeP...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Sumber : https://32n.co/blog/installing-freepbx-and-asterisk-on-ubuntu-22-04-lts/
# FreePBX and Asterisk installation 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.

    1. 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.
    1. Step 1: Update the system

The system should first be updated so that installed packages are current.

```bash apt-get update -y apt-get upgrade -y ```

    1. Step 2: Set the hostname

Set the hostname of the server to `freepbx`:

```bash 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.

    1. 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:

```bash sudo swapon --show free -h df -h ```

Create a 2 GB swap file:

```bash sudo fallocate -l 2G /swapfile ls -lh /swapfile ```

Set the appropriate permissions:

```bash sudo chmod 600 /swapfile ls -lh /swapfile ```

Initialize and enable the swap file:

```bash sudo mkswap /swapfile sudo swapon /swapfile sudo swapon --show free -h ```

Back up the existing `/etc/fstab` file:

```bash sudo cp /etc/fstab /etc/fstab.bak ```

Add the swap file to `/etc/fstab` so that it is automatically enabled after a reboot:

```bash echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab ```

The Linux virtual-memory parameters can be adjusted in `/etc/sysctl.conf`:

```bash sudo nano /etc/sysctl.conf ```

Add the following values:

```text vm.swappiness=10 vm.vfs_cache_pressure=50 ```

The resulting configuration can be inspected with:

```bash cat /etc/sysctl.conf ```

    1. Step 4: Reboot the system

Reboot the server to apply the system configuration changes:

```bash reboot ```

    1. Step 5: Install Asterisk

Install the packages required to compile Asterisk and provide several of its optional components:

```bash 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:

```bash wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gz ```

Extract the archive:

```bash tar -xvzf asterisk-20-current.tar.gz ```

Change to the extracted Asterisk source directory:

```bash cd asterisk-20.* ```

Download the MP3 source required for MP3 support:

```bash contrib/scripts/get_mp3_source.sh ```

Install the Asterisk prerequisite packages:

```bash contrib/scripts/install_prereq install ```

Configure the Asterisk build:

```bash ./configure ```

Open the Asterisk module-selection interface:

```bash make menuselect ```

Compile and install Asterisk:

```bash 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.

    1. Step 6: Configure Asterisk

A dedicated system user and group are used to run Asterisk.

Create the Asterisk group:

```bash groupadd asterisk ```

Create the Asterisk system user:

```bash useradd -r -d /var/lib/asterisk -g asterisk asterisk ```

Add the Asterisk user to the `audio` and `dialout` groups:

```bash usermod -aG audio,dialout asterisk ```

Change ownership of the Asterisk configuration, library, log, and spool directories:

```bash 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:

```bash nano /etc/default/asterisk ```

Set the following values:

```text 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:

```bash nano /etc/asterisk/asterisk.conf ```

Set the following values:

```text runuser = asterisk rungroup = asterisk ```

Restart Asterisk and enable it to start automatically with the system:

```bash systemctl restart asterisk systemctl enable asterisk systemctl status asterisk ```

      1. Correct common configuration errors

The following commands modify the Asterisk CDR and CEL configuration files to correct common RADIUS-related configuration issues:

```bash 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:

```bash systemctl start asterisk asterisk -rvv ```

After verifying the Asterisk CLI, leave it with:

```text exit ```

    1. Step 7: Install FreePBX dependencies

FreePBX requires a web server, database server, PHP, and several PHP extensions.

Install `software-properties-common`:

```bash apt install software-properties-common ```

Add the Ondřej Surý PHP repository:

```bash add-apt-repository ppa:ondrej/php -y ```

Install Apache HTTP Server, MariaDB, PHP 7.4, and the required PHP extensions:

```bash 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 ```

      1. Configure PHP 7.4 as the default PHP version

Disable the currently enabled Apache PHP modules:

```bash sudo a2dismod php* ```

Enable the PHP 7.4 Apache module:

```bash sudo a2enmod php7.4 ```

Restart Apache:

```bash sudo systemctl restart apache2 ```

Set PHP 7.4 as the default command-line PHP version:

```bash 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 ```

    1. Step 8: Download and install FreePBX

Download the latest FreePBX 16 release available from the specified FreePBX mirror:

```bash wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-16.0-latest.tgz ```

Extract the archive:

```bash tar -xvzf freepbx-16.0-latest.tgz ```

Change to the FreePBX source directory:

```bash cd freepbx ```

Install Node.js and npm:

```bash apt-get install nodejs npm -y ```

Run the FreePBX installer:

```bash ./install -n ```

Install the FreePBX PM2 module:

```bash fwconsole ma install pm2 ```

      1. Configure Apache

Set the Apache process to use the `asterisk` user and group:

```bash sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf ```

Enable Apache directory overrides:

```bash sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf ```

Enable Apache URL rewriting:

```bash a2enmod rewrite ```

Restart Apache:

```bash systemctl restart apache2 ```

    1. 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`:

```bash sed -i 's/\(^upload_max_filesize = \).*/\512M/' /etc/php/7.4/apache2/php.ini ```

Apply the same setting to the PHP CLI configuration:

```bash sed -i 's/\(^upload_max_filesize = \).*/\512M/' /etc/php/7.4/cli/php.ini ```

Set the PHP memory limit for Apache:

```bash sed -i 's/\(^memory_limit = \).*/\1512M/' /etc/php/7.4/apache2/php.ini ```

Set the PHP CLI memory limit:

```bash sed -i 's/\(^memory_limit = \).*/\1512M/' /etc/php/7.4/cli/php.ini ```

Restart Apache to apply the PHP configuration:

```bash systemctl restart apache2 ```

    1. 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:

```bash fwconsole moduleadmin ```

The available modules can also be examined with:

```bash 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.

    1. 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 releases are published.