Book Image

FreePBX 2.5 Powerful Telephony Solutions

By : Alex Robar
Book Image

FreePBX 2.5 Powerful Telephony Solutions

By: Alex Robar

Overview of this book

FreePBX is an easy-to-use GUI that controls and manages Asterisk. It gives you pre-programmed functionality accessible through user-friendly web interfaces that allows you to have a fully functional PBX pretty much straight away with no programming. With this book it's easy to master the many features of FreePBX, which will help you to save time and money as you set up your enterprise-class network. This book will guide you through these features to install, configure, and maintain a professional PBX with plenty of examples and screenshots. By the end of this book, you will have learned to create an enterprise-class VoIP PBX that features the stability and feature set of traditional telephony systems without the hefty price tag. This book will help its readers to roll out a robust, web-based, and inexpensive yet powerful telephony solution through the GUI. By following the practical examples in this book, you will learn how to install, configure, and manage an enterprise-class PBX using open source telephony tools Asterisk and FreePBX. From here on, this book takes a closer look at the open source telephony engine software, discussing a broad range of topics from how to build and deploy an enterprise-class VoIP PBX to creating VoIP trunks using SIP, IAX2, and ZAP technologies and setting up user extensions with voicemail. FreePBX 2.5 Powerful Telephony Solutions will introduce you to advanced options such as call routing, voicemail, and other calling features. Finally, this book will provide you with the relevant information to help you personalize and secure your PBX.
Table of Contents (20 chapters)
FreePBX 2.5 Powerful Telephony Solutions
Credits
About the Author
About the Reviewer
Preface
Voicemail.conf Options

Installing FreePBX on Ubuntu Server 8.10


Ubuntu Server is a popular and stable operating system based on Debian GNU/Linux. It is becoming increasingly popular for general-purpose server deployments, and is a good choice for an Asterisk/FreePBX server.

Ubuntu Server 8.10 should be installed with the following options:

  • DNS server

  • LAMP server

  • Mail server

  • OpenSSH server

Once you have a clean Ubuntu Server 8.10 install to work from, the prerequisite packages can be installed.

Prerequisite packages

FreePBX requires several prerequisite packages to install and function properly. Most prerequisite packages are not included in standard Linux distribution installations, but all should be available in your distributions package management system.

The first important step is to update your system, ensuring that all security updates are installed and all installed packages are at the latest version. To update all of the installed packages on Ubuntu Server 8.10, log in as the standard user that you created during the setup, and type the following into the system console:

sudo aptitude update
sudo aptitude upgrade -y

Enter your user account password when prompted.

The system will proceed to download and install any of the packages that have been updated since the release of your operating system. Depending on how many updates are required and the speed of your Internet connection, this process can take anything from a few minutes to several hours.

Once the system is fully up to date, it is a good idea to reboot so that the updated services can restart and newer kernels can be booted. To reboot, type the following into the console:

sudo reboot

Now that the system is up to date, the required prerequisite libraries and packages can be installed. To install the required prerequisite packages on Ubuntu Server 8.10, log in as a standard user and type the following:

sudo aptitude install build-essential autoconf automake libtool flex bison libssl-dev libnewt-dev libncurses5-dev linux-headers-$(uname -r) sox curl mysql-client libmysqlclient-dev php5 php5-cli php5-gd php5-curl php5-mcrypt php5-xmlrpc php5-mhash php5-suhosin php5-common php5-xsl libapache2-mod-php5 php-pear lame subversion -y

Note

Note that all of the above is a single aptitude command, and should be typed as if it was written on a single line.

Now that all prerequisite packages are installed, we can install Asterisk.

First, switch to the /usr/src directory by typing the following into the console:

cd /usr/src

Note

Install Asterisk from source

Many Linux distributions provide Asterisk and its dependent libraries in their package management systems. It is recommended that Asterisk, Asterisk-Addons, LibPRI, and Zaptel always be compiled and installed from source. This avoids improperly built or outdated installations.

A core Asterisk installation consists of four components—Asterisk, Asterisk-Addons, DAHDI, and LibPRI:

  • "Asterisk" is the main Asterisk routing engine

  • Asterisk-Addons component contains commonly used Asterisk applications (such as the application that writes CDR records to a MySQL database, which FreePBX uses)

  • DAHDI is the Digium Asterisk Hardware Device Interface package, which allows Asterisk to communicate with additional telephony hardware devices (such as analog trunk cards)

  • The LibPRI package enables Asterisk to interface with PRI, BRI, and QSIG trunks

Type the following into the console to download the source code for Asterisk, Asterisk-Addons, DAHDI, and LibPRI:

sudo wget http://downloads.digium.com/pub/asterisk/asterisk-1.4-current.tar.gz
sudo wget http://downloads.digium.com/pub/asterisk/asterisk-addons-1.4-current.tar.gz
sudo wget http://downloads.digium.com/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
sudo wget http://downloads.digium.com/pub/libpri/libpri-1.4-current. tar.gz

Extract the source code:

sudo tar zxf asterisk-1.4-current.tar.gz
sudo tar zxf asterisk-addons-1.4-current.tar.gz
sudo tar zxf zaptel-1.4-current.tar.gz
sudo tar zxf libpri-1.4-current.tar.gz

Compile and install the DAHDI telephony hardware interface modules:

cd dahdi-linux-complete-2.* sudo make all sudo make install make config

Compile and install Asterisk:

cd ../asterisk-1.4.* ./configure sudo make install make samples

Compile and install the Asterisk-Addons modules:

cd ../asterisk-addons-1.4.* ./configure sudo make install

Compile and install the LibPRI modules:

cd ../libpri-1.4.* make sudo make install

The PEAR DB module is installed through PEAR software by typing the following into the console:

pear install db

Finally, we start Asterisk as a background process by typing:

asterisk &

Note that this method of starting Asterisk is only temporary. Once installed, the FreePBX startup script will be configured to run at boot.

Setting up the database

FreePBX utilizes a MySQL database to store all of the configurations shown in the web interface it provides.

Under Ubuntu Server 8.10, MySQL must simply be started. A MySQL root password is entered during the Ubuntu install process, and Ubuntu automatically sets up the MySQL service to start at boot time. To start MySQL, type the following command:

/etc/init.d/invoke-rc.d mysql start

A separate user account under which Asterisk can run should also be created. It is common for Asterisk to run as the root user on a system (and almost always an easier way to make things work), but it is a security risk. Should Asterisk or Apache be compromised by a remote exploit, the flaw cannot be used to take over the entire server when Asterisk runs as its own user. Create a user account called asterisk that Asterisk will run as, using the following command:

adduser -gecos "Asterisk PBX" --home /var/lib/asterisk --system --group asterisk

Note

Note that all of the above is a single adduser command, and should be typed as if it was written on a single line.

Create a database to store Asterisk configuration and another to store call detail records:

mysqladmin -u root -p create asterisk
mysqladmin -u root -p create asteriskcdrdb

Enter your MySQL root password when prompted.

FreePBX has created prepared SQL statements to set up the structure of each database it uses. Type the following to switch to the /usr/src directory and download the FreePBX installer archive:

cd /usr/src
sudo wget http://internap.dl.sourceforge.net/sourceforge/amportal/freepbx-2.5.1.tar.gz

The above command will download FreePBX version 2.5.1. To check for the current version of FreePBX, visit the site http://freepbx.org/download-freepbx. The current version will be listed next to the Download FreePBX button. If the listed version is newer than 2.5.1, it should be used instead.

Extract FreePBX using the following command:

tar zxf freepbx-2.5.1.tar.gz

Switch to the FreePBX SQL directory:

cd freepbx-2.5.1/SQL

The two prepared statements provided by FreePBX are newinstall.sql and cdr_mysql_table.sql. The newinstall.sql file contains the necessary SQL statements to create the tables that store all FreePBX configuration data (extensions, call targets, call routing information, etc.). The cd_mysql_table.sql file contains one single statement that creates a CDR table for storing all call details records. To run the SQL statements contained in these files, run the following commands:

mysql -u root -p asterisk < newinstall.sql
mysql -u root -p asteriskcdrdb < cdr_mysql_table.sql

Enter your MySQL root password when prompted.

Now we must grant the Asterisk user permissions on the Asterisk and Asterisk CDR databases. FreePBX will not function without this access. To grant permissions, we must first drop to a MySQL shell:

mysql -u root -p

Enter your MySQL root password when prompted.

Once at the MySQL shell, type the following commands to grant the appropriate privileges to the Asterisk user. Remember to replace freepbxdbpassword with a password of your choice and note that the password should be enclosed in single quotes.

mysql> GRANT ALL PRIVILEGES ON asterisk.* TO asterisk@localhost IDENTIFIED BY 'freepbxdbpassword';
mysql> GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asterisk@localhost IDENTIFIED BY 'freepbxdbpassword';
mysql> flush privileges;
mysql> \q

Setting up file permissions

The final installation step is to set up appropriate permissions and general configurations. To make the required configuration changes, the examples shown as follows make use of the sed command. The sed command can take a stream of input and rewrite it on the fly based on patterns listed in the command. The syntax for the following sed commands used works as follows:

sed -i "s/pattern_to_find/replacement_pattern/" /path/to/file

The -i option tells sed to edit the input file in place, such that the listed file is changed and a new file with the requested changes is not created in its place.

The s/ tells sed that we are looking to replace a specific pattern with text of our own.

The pattern_to_find token should be replaced by the text that we are searching for. This can be a normal alphanumeric pattern, or a regular expression.

The replacement_pattern token should be replaced with the value that we want to replace the pattern_to_find token with.

As FreePBX will need to interact with Asterisk, the Apache web server must be set up to run as the asterisk user. To change the user and the group that Apache runs as, enter the following commands as the root user:

sed -i "s/www-data/asterisk/" /etc/apache2/envvars

We must also allow FreePBX to override various default Apache directives. To allow the directive overrides, type the following into the console:

sed -i "s/AllowOverride None/AllowOverride All/" /etc/apache2/apache2.conf

The Asterisk run directory (where the Asterisk PID file will be stored) should be changed to /var/run/asterisk:

sed -i "s/astrundir => \/var\/run/astrundir => \/var\/run\/asterisk/" /etc/asterisk/asterisk.conf

PHP will need to be configured to allow for large file uploads up to 20 MB, as FreePBX modules can reach above the default 8 MB limit. To change the PHP limits type the following:

sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php5/apache2/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php5/apache2/php.ini

The Asterisk run directory (where the process ID file is stored) is located on a temporary file system under Ubuntu. Each time the server reboots, the directory will disappear along with its associated permissions. To correct this, the directory must be created and permissions set at boot time:

echo "mkdir /var/run/asterisk" >> /etc/rc.local
echo "chown -R asterisk:asterisk /var/run/asterisk" >> /etc/rc.local

Note

Note that the chown statement as above is one command and should be typed on a single line.

Finally, the asterisk user should be set up as the owner of several directories that Asterisk will use during normal operation:

chown -R asterisk:asterisk /var/spool/asterisk/
chown -R asterisk:asterisk /var/log/asterisk/

At this point, all packages should be installed and configured correctly. It is recommended that your server be rebooted now to allow all changes to take effect.

FreePBX base installation

Now that we have a working Linux install, all prerequisite packages, and a functioning MySQL database, we can finally install FreePBX. As FreePBX has already been downloaded, the process is simply to switch to the FreePBX directory and run the installer:

cd /usr/src/freepbx-2.5.1
./install_amp install

You will be asked a series of configuration questions that the installer uses to generate a configuration file located at /etc/amportal.conf. If a mistake is made during the question and answer part of the installation, simply remove this file using the following command, and run the install_amp install command:

rm -f /etc/amportal.conf


Question

Suggested answer

Enter your USERNAME to connect to the 'asterisk' database

The username we set up with permissions on the asterisk database is simply called asterisk. Type "asterisk" and hit the Enter key.

Enter your PASSWORD to connect to the 'asterisk' database

This is the password that you setup during the grant all privileges step for the Asterisk database. Type your password and hit the Enter key.

Enter the hostname of 'asterisk' database

This is the location of your MySQL server. Using the setup listed in this book, this will be localhost (as the MySQL server resides on the same server as the Apache server does). If the MySQL server resides on a different server than Apache, the answer to this question should be the hostname or IP address of the server where MySQL resides. Type the hostname or IP address of the server running MySQL and hit the Enter key.

Enter a USERNAME to connect to the Asterisk Manager Interface

Pick a username that FreePBX can use to communicate with the Asterisk Manager Interface. Leaving this as "admin" is fine. Type the desired username and press the Enter key.

Enter a PASSWORD to connect to the Asterisk Manager Interface

Pick a password that FreePBX will use when communicating with the Asterisk Manager Interface. It is strongly recommended that the password be changed from the default of "amp111". Type your desired password and press the Enter key.

Enter the path to use for your AMP web root

This is the location of your Apache root folder. By default, Ubuntu Server 8.10 will place this in /var/www. Type your web root and press the Enter key.

Enter the IP ADDRESS or hostname used to access the AMP web-admin

This is the IP address or hostname that you have assigned to your Asterisk server. This is usually the IP address that you will type into your browser to view the FreePBX web interface when you are ready to configure your Asterisk PBX. Type your IP address or hostname and press the Enter key.

Enter a PASSWORD to perform call transfers with the Flash Operator Panel

The Flash Operator Panel is a visual switchboard that allows you to view activity on your PBX, as well as bridge, transfer, or disconnect calls. It is strongly recommended that you change this default password value. Type your desired password and press the Enter key.

Use simple Extensions [extensions] admin or separate Devices and Users [deviceanduser]

FreePBX can associate one user to one device (extensions mode) or one user to many devices (deviceanduser mode). This value can always be changed at any time, and the differences will be discussed later in this book. For now, it is recommended to leave the default value of "extensions" and push the Enter key.

Enter directory in which to store AMP executable scripts

This is the directory in which FreePBX will store any scripts that execute against the system. Unless your system calls for a specific change to this location, it is recommended to leave this at the default value of /var/lib/asterisk/bin and press the Enter key.

At this point, the FreePBX installer will run through the rest of the install process automatically. As the final step, we need to configure FreePBX to start automatically when the system boots:

echo "/usr/sbin/amportal start &" > /etc/rc.local