|
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.sourceforg ... e/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.
Setting up the databaseFreePBX 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.n ... reepbx-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 <code>SQL</code> 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
Setting up file permissionsThe 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.
|
|