FreePBX is a dynamic software package that uses the power of Linux, Apache, MySQL, and PHP to bring form to the function of Asterisk. Before we dive into the heart of administering a FreePBX system, we have a few steps to complete in order to install and configure these frameworks. Though going from a fresh Linux install to a working Asterisk and FreePBX phone server is a relatively straightforward process, it is advisable to be careful. The steps in this chapter form the foundation of your server and their successful completion is critical to the stability of your Asterisk and FreePBX installations.
While every deployment is going to be different and have different requirements, the steps in this chapter will provide installation instructions for CentOS 5.2 and Ubuntu Server 8.10.
The Community ENTerprise Operating System (CentOS) is a secure, stable OS based on Red Hat Enterprise Linux. CentOS is a popular choice for Asterisk/FreePBX systems. CentOS 5.2 should be installed with the following packages selected:
All of the other groups and packages should be unchecked during installation, as they are not required and may have an impact on the performance. SELinux should also be disabled during CentOS installation.
Once you have a clean CentOS 5.2 install to work from, the prerequisite packages can be installed.
FreePBX requires several prerequisite packages for being installed and functioning properly. Most prerequisite packages are not included in standard Linux distribution installations, but all of them should be available in your distribution's package management system.
The first important step is to update your system, ensuring that all security updates are installed and that all the installed packages are at their latest version. To update all the installed packages on CentOS 5.2, log in as root and type the following command into the system console:
yum update -y
The system will proceed to download and install any 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 anywhere 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. In order to reboot, type the following into the console:
shutdown -r now
Now that the system is up to date, the required prerequisite libraries and packages can be installed. As long as the correct base packages were selected during the installation of CentOS, FreePBX will only require the following additional packages:
Package |
Purpose |
---|---|
LibTIFF development headers |
Used for dynamic generation of images (such as call usage graphs) |
PHP GD library |
As with LibTIFF, the GD libraries are used by PHP to dynamically generate images |
PHP MySQL library |
Allows FreePBX to read and write to its MySQL database backend |
Kernel or SMP kernel development headers |
Used to allow DAHDI to build its modules against the running kernel |
Audio file development headers |
Allows FreePBX to transcode recordings and music-on-hold files when they are uploaded |
MySQL development headers |
These headers are required when building applications that use MySQL databases (FreePBX is based on a MySQL database backend) |
To install the required prerequisite packages for CentOS 5.2, log in as root and type the following:
yum install libtiff-devel php-gd php-mysql php-pear kernel-devel kernel-smp-devel audiofile-devel mysql-devel -y
Note
Note that all of the above is a single yum
command, and should be typed as if it was written on a single line.
Now that all of the prerequisite packages are installed, we can install Asterisk. First, switch to the /usr/src
directory by typing the following into the console:
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 should 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:
wget http://downloads.digium.com/pub/asterisk/asterisk-1.4-current.tar.gz
wget http://downloads.digium.com/pub/asterisk/asterisk-addons-1.4-current.tar.gz
wget http://downloads.digium.com/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
wget http://downloads.digium.com/pub/libpri/libpri-1.4-current.tar.gz
Extract the source code:
tar zxf asterisk-1.4-current.tar.gz
tar zxf asterisk-addons-1.4-current.tar.gz
tar zxf dahdi-linux-complete-current.tar.gz
tar zxf libpri-1.4-current.tar.gz
Compile and install the DAHDI telephony hardware interface modules:
cd dahdi-linux-complete-2.*
make all
make install
make config
Compile and install Asterisk with the following commands:
cd ../asterisk-1.4.*
./configure
make install
make samples
Compile and install the Asterisk-Addons modules (contains the application that FreePBX uses to write call detail records to the MySQL database):
cd ../asterisk-addons-1.4.*
./configure
make install
Compile and install the LibPRI modules for PRI, BRI, and QSIG interface support:
cd ../libpri-1.4.*
make
make install
PHP Extension and Application Repository (PEAR) is a repository and distribution system for various reusable PHP libraries. PEAR contains a module called "DB", which abstracts calls away from a particular database engine (allowing the same database code to be used against different database backends). FreePBX uses the PEAR DB module to allow its code to be used with both MySQL and PostgreSQL currently (with the possibility of additional database engines in the future). The module is installed through PEAR by typing the following into the console:
pear install db
The final prerequisite is the LAME MP3 encoder. LAME is left out of the CentOS package management system. So, like Asterisk, it should be compiled from source. The latest version of LAME can be found by visiting the site http://lame.sourceforge.net/. If the latest version is newer than 3.98.2, then the newer version should be used instead. Type the following into the console to switch to the /usr/src
directory and download LAME:
cd /usr/src
wget http://superb-east.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz
Extract LAME using the following command:
tar zxf lame-398-2.tar.gz
Compile and install LAME:
cd lame-398-2
./configure
make
make install
Finally, we start Asterisk as a background process by typing the following into the console:
asterisk &
Note that this method of starting Asterisk is only temporary. Once installed, the FreePBX startup script will be configured to start at boot.
FreePBX utilizes a MySQL database to store all the configurations shown in the web interface it provides.
Under CentOS 5.2, the MySQL engine is neither started nor set up to start at boot. We must first start the MySQL database engine and then set it to start at boot time. If this is not done, not only will MySQL have to be manually started each time the system needs to be administered, but also the system will not log any calls (all CDRs are written to a MySQL database):
/etc/init.d/mysqld start
chkconfig mysqld on
A root password must be set for MySQL. The root MySQL user has full administrative access to all of the databases on the system. Therefore, leaving the root password blank leaves a very large security hole:
mysqladmin -u root password newpassword
Replace newpassword
with the password you would like to set for the MySQL root user.
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 that is usually an easier way to make things work), but this 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:
useradd -c "Asterisk PBX" -d /var/lib/asterisk asterisk
Use the mysqladmin
command to 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
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 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:
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 of the FreePBX configuration data (extensions, call targets, call routing information, and so on). The cd_mysql_table.sql
file contains one single statement that creates a CDR table for storing all call detail records. To run the SQL statements contained in these files, type the following commands into the console:
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 as follows:
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
The final installation step is to set up appropriate permissions and general configurations. To make the required configuration changes, the following examples 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/User apache/User asterisk/" /etc/httpd/conf/httpd.conf
sed -i "s/Group apache/Group asterisk/" /etc/httpd/conf/httpd.conf
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/httpd/conf/httpd.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
We must also create the /var/run/asterisk
directory so that Asterisk can write its PID file there (as we have just configured it to):
mkdir /var/run/asterisk
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 into the console:
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php.ini
Finally, the asterisk
user should be set up as the owner of several directories that Asterisk will use during the normal operation:
chown -R asterisk:asterisk /var/spool/asterisk/
chown -R asterisk:asterisk /var/log/asterisk/
chown -R asterisk:asterisk /var/run/asterisk/
At this point, all packages should be installed and configured correctly. It is recommended that your server be rebooted now, to allow all the changes to take effect.
Now that we have a working Linux install, all the 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 once again:
rm -f /etc/amportal.conf
Question |
Suggested answer |
---|---|
|
This is the username you set up with permissions on the Asterisk database and is simply called |
|
This is the password you set up during the |
|
This is the location of your MySQL server. Using the setup listed in this book, this will be |
|
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. |
|
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 |
|
This is the location of your Apache root folder. By default, CentOS 5.2 will place this in |
|
It is the IP address or hostname that you have assigned to your Asterisk server. It 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. |
|
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. |
|
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 |
|
This is the directory in which FreePBX will store any script that executes 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 |
|
This is the directory in which FreePBX will store any scripts that execute against the system with root privileges. As with the previous configuration question, unless your setup calls for a specific change to this value, leave it at the default of |
At this point, the FreePBX installer will run through the rest of the installation process automatically. As the final step, we need to configure FreePBX to start automatically when the system boots:
echo "/usr/local/sbin/amportal start" >> /etc/rc.local
The Community ENTerprise Operating System (CentOS) is a secure, stable OS based on Red Hat Enterprise Linux. CentOS is a popular choice for Asterisk/FreePBX systems. CentOS 5.2 should be installed with the following packages selected:
All of the other groups and packages should be unchecked during installation, as they are not required and may have an impact on the performance. SELinux should also be disabled during CentOS installation.
Once you have a clean CentOS 5.2 install to work from, the prerequisite packages can be installed.
FreePBX requires several prerequisite packages for being installed and functioning properly. Most prerequisite packages are not included in standard Linux distribution installations, but all of them should be available in your distribution's package management system.
The first important step is to update your system, ensuring that all security updates are installed and that all the installed packages are at their latest version. To update all the installed packages on CentOS 5.2, log in as root and type the following command into the system console:
yum update -y
The system will proceed to download and install any 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 anywhere 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. In order to reboot, type the following into the console:
shutdown -r now
Now that the system is up to date, the required prerequisite libraries and packages can be installed. As long as the correct base packages were selected during the installation of CentOS, FreePBX will only require the following additional packages:
Package |
Purpose |
---|---|
LibTIFF development headers |
Used for dynamic generation of images (such as call usage graphs) |
PHP GD library |
As with LibTIFF, the GD libraries are used by PHP to dynamically generate images |
PHP MySQL library |
Allows FreePBX to read and write to its MySQL database backend |
Kernel or SMP kernel development headers |
Used to allow DAHDI to build its modules against the running kernel |
Audio file development headers |
Allows FreePBX to transcode recordings and music-on-hold files when they are uploaded |
MySQL development headers |
These headers are required when building applications that use MySQL databases (FreePBX is based on a MySQL database backend) |
To install the required prerequisite packages for CentOS 5.2, log in as root and type the following:
yum install libtiff-devel php-gd php-mysql php-pear kernel-devel kernel-smp-devel audiofile-devel mysql-devel -y
Note
Note that all of the above is a single yum
command, and should be typed as if it was written on a single line.
Now that all of the prerequisite packages are installed, we can install Asterisk. First, switch to the /usr/src
directory by typing the following into the console:
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 should 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:
wget http://downloads.digium.com/pub/asterisk/asterisk-1.4-current.tar.gz
wget http://downloads.digium.com/pub/asterisk/asterisk-addons-1.4-current.tar.gz
wget http://downloads.digium.com/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
wget http://downloads.digium.com/pub/libpri/libpri-1.4-current.tar.gz
Extract the source code:
tar zxf asterisk-1.4-current.tar.gz
tar zxf asterisk-addons-1.4-current.tar.gz
tar zxf dahdi-linux-complete-current.tar.gz
tar zxf libpri-1.4-current.tar.gz
Compile and install the DAHDI telephony hardware interface modules:
cd dahdi-linux-complete-2.*
make all
make install
make config
Compile and install Asterisk with the following commands:
cd ../asterisk-1.4.*
./configure
make install
make samples
Compile and install the Asterisk-Addons modules (contains the application that FreePBX uses to write call detail records to the MySQL database):
cd ../asterisk-addons-1.4.*
./configure
make install
Compile and install the LibPRI modules for PRI, BRI, and QSIG interface support:
cd ../libpri-1.4.*
make
make install
PHP Extension and Application Repository (PEAR) is a repository and distribution system for various reusable PHP libraries. PEAR contains a module called "DB", which abstracts calls away from a particular database engine (allowing the same database code to be used against different database backends). FreePBX uses the PEAR DB module to allow its code to be used with both MySQL and PostgreSQL currently (with the possibility of additional database engines in the future). The module is installed through PEAR by typing the following into the console:
pear install db
The final prerequisite is the LAME MP3 encoder. LAME is left out of the CentOS package management system. So, like Asterisk, it should be compiled from source. The latest version of LAME can be found by visiting the site http://lame.sourceforge.net/. If the latest version is newer than 3.98.2, then the newer version should be used instead. Type the following into the console to switch to the /usr/src
directory and download LAME:
cd /usr/src
wget http://superb-east.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz
Extract LAME using the following command:
tar zxf lame-398-2.tar.gz
Compile and install LAME:
cd lame-398-2
./configure
make
make install
Finally, we start Asterisk as a background process by typing the following into the console:
asterisk &
Note that this method of starting Asterisk is only temporary. Once installed, the FreePBX startup script will be configured to start at boot.
FreePBX utilizes a MySQL database to store all the configurations shown in the web interface it provides.
Under CentOS 5.2, the MySQL engine is neither started nor set up to start at boot. We must first start the MySQL database engine and then set it to start at boot time. If this is not done, not only will MySQL have to be manually started each time the system needs to be administered, but also the system will not log any calls (all CDRs are written to a MySQL database):
/etc/init.d/mysqld start
chkconfig mysqld on
A root password must be set for MySQL. The root MySQL user has full administrative access to all of the databases on the system. Therefore, leaving the root password blank leaves a very large security hole:
mysqladmin -u root password newpassword
Replace newpassword
with the password you would like to set for the MySQL root user.
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 that is usually an easier way to make things work), but this 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:
useradd -c "Asterisk PBX" -d /var/lib/asterisk asterisk
Use the mysqladmin
command to 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
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 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:
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 of the FreePBX configuration data (extensions, call targets, call routing information, and so on). The cd_mysql_table.sql
file contains one single statement that creates a CDR table for storing all call detail records. To run the SQL statements contained in these files, type the following commands into the console:
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 as follows:
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
The final installation step is to set up appropriate permissions and general configurations. To make the required configuration changes, the following examples 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/User apache/User asterisk/" /etc/httpd/conf/httpd.conf
sed -i "s/Group apache/Group asterisk/" /etc/httpd/conf/httpd.conf
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/httpd/conf/httpd.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
We must also create the /var/run/asterisk
directory so that Asterisk can write its PID file there (as we have just configured it to):
mkdir /var/run/asterisk
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 into the console:
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php.ini
Finally, the asterisk
user should be set up as the owner of several directories that Asterisk will use during the normal operation:
chown -R asterisk:asterisk /var/spool/asterisk/
chown -R asterisk:asterisk /var/log/asterisk/
chown -R asterisk:asterisk /var/run/asterisk/
At this point, all packages should be installed and configured correctly. It is recommended that your server be rebooted now, to allow all the changes to take effect.
Now that we have a working Linux install, all the 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 once again:
rm -f /etc/amportal.conf
Question |
Suggested answer |
---|---|
|
This is the username you set up with permissions on the Asterisk database and is simply called |
|
This is the password you set up during the |
|
This is the location of your MySQL server. Using the setup listed in this book, this will be |
|
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. |
|
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 |
|
This is the location of your Apache root folder. By default, CentOS 5.2 will place this in |
|
It is the IP address or hostname that you have assigned to your Asterisk server. It 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. |
|
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. |
|
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 |
|
This is the directory in which FreePBX will store any script that executes 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 |
|
This is the directory in which FreePBX will store any scripts that execute against the system with root privileges. As with the previous configuration question, unless your setup calls for a specific change to this value, leave it at the default of |
At this point, the FreePBX installer will run through the rest of the installation process automatically. As the final step, we need to configure FreePBX to start automatically when the system boots:
echo "/usr/local/sbin/amportal start" >> /etc/rc.local
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.
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.
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
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
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.
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 |
---|---|
|
The username we set up with permissions on the asterisk database is simply called |
|
This is the password that you setup during the |
|
This is the location of your MySQL server. Using the setup listed in this book, this will be |
|
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. |
|
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. |
|
This is the location of your Apache root folder. By default, Ubuntu Server 8.10 will place this in |
|
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. |
|
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. |
|
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. |
|
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 |
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
By now, we should have a fully functional Linux server running Apache, MySQL, Asterisk, and FreePBX. Asterisk should be running under a dedicated user account for additional security. Congratulations! Installation is often the most difficult part of configuring a FreePBX system.
In the next chapter, we delve into the ins and outs of maintaining a FreePBX system by learning about installing, removing, and updating modules.