Asterisk Freepbx on Ubuntu

This guide covers the installation of Asterisk®from source on Ubuntu.  Changes in this guide compared to previous guides include the use of Ubuntu v14, Asterisk v12 & v13, Freepbx v12, and the addition of the pjsip library.

Tested on:

Ubuntu Server v14.04 LTS 32bit & 64bit
Asterisk v12 & v13
FreePBX v12

Assumptions:

Console text mode (init 3)
Installation done as root user (#)

Install Prerequisites

Ensure all required packages are installed. 

apt-get update && apt-get install whiptail -y && apt-get upgrade -y && apt-get dist-upgrade -y && reboot
apt-get install -y build-essential autoconf automake curl lua5.1 linux-headers-generic libncurses-dev zlib1g-dev libssl-dev libxml2-dev libsqlite3-dev uuid-dev libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev libasound2-dev portaudio19-dev libcurl4-gnutls-dev libpq-dev unixodbc-dev libsqlite3-dev libmysqlclient-dev libneon27-dev libgmime-2.6-dev libusb-dev liblua5.1-0-dev libgtk2.0-dev libmysqlclient-dev libbluetooth-dev libradiusclient-ng-dev freetds-dev libsnmp-dev libiksemel-dev libcorosync-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev libjack-dev libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev libedit-dev libjansson-dev libldap-dev libxslt1-dev libmyodbc doxygen subversion git mpg123 e2fsprogs php5 php5-curl sqlite3 uuid php5-cli php5-mysql php5-gd php-pear sox bison flex tftpd mailutils nano ntp apache2 mysql-client mysql-server postfix sudo xmlstarlet

Set mysql root password when asked to prevent it from repeatedly asking.  Use internet site for postfix mail configuration.

Set timezone

dpkg-reconfigure tzdata

Download and install source files

DAHDI

Only required if using a physical server and installing telecom hardware.

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
tar zxvf dahdi-linux-complete*
cd /usr/src/dahdi-linux-complete*/
make && make install && make config
service dahdi start

PJSIP

cd /usr/src
wget http://www.pjsip.org/release/2.5.5/pjproject-2.5.5.tar.bz2
tar -xjvf pjproject*
cd /usr/src/pjproject*/

#If this is a new source install the following command won't do anything
make distclean
./configure --prefix=/usr --enable-shared --disable-sound --disable-resample \
--disable-video --disable-opencore-amr CFLAGS='-O2 -DNDEBUG'
make uninstall && make dep && make && make install && ldconfig

To verify type ldconfig -p | grep pj which should show several linked *.so files in /usr/lib.

Asterisk

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
tar zxvf asterisk-13-current.tar.gz
cd /usr/src/asterisk-13*/
make distclean
./configure

If ./configure fails with cannot find ptlib-config then use./configure --without-pwlib which is only required if you need to support H.323.

cd /usr/src/asterisk-13*/
make menuselect.makeopts

#To select compile options manually run make menuselect instead of the following command
#To list command line options run menuselect/menuselect --list-options
#If Asterisk fails to run on a virtual machine try add "--disable BUILD_NATIVE"
#To add asterisk realtime for applications such as A2billing add "--enable res_config_mysql"

menuselect/menuselect --enable cdr_mysql --enable EXTRA-SOUNDS-EN-GSM menuselect.makeopts

Create Asterisk user, compile, install, and set ownership.

adduser asterisk --disabled-password --no-create-home --home /var/lib/asterisk --shell \
/sbin/nologin --gecos "Asterisk User"
make && make install && chown -R asterisk. /var/lib/asterisk

Freepbx GUI

pear install db-1.7.14

If the DB fails to install try gunzip /build/buildd/php5-5.5.9+dfsg/pear-build-download/*.tgz followed by pear upgrade /build/buildd/php5-5.5.9+dfsg/pear-build-download/*.tar  

VERSION=12.0
USERNAME=asteriskuser
PASSWORD=amp109

#The following commands must be entered one at a time in order to enter the mysql root password
mysqladmin -p create asterisk
mysqladmin -p create asteriskcdrdb
mysql -p -e "GRANT ALL PRIVILEGES ON asterisk.* TO $USERNAME@localhost IDENTIFIED BY '$PASSWORD';"
mysql -p -e "GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO $USERNAME@localhost IDENTIFIED BY '$PASSWORD';"
mysql -p -e "flush privileges;"

cd /usr/src
git clone -b release/$VERSION https://github.com/FreePBX/framework.git freepbx

cd /usr/src/freepbx
./start_asterisk start
mv /var/www/html /var/www/html_orig
./install_amp --installdb --skip-module-install --username $USERNAME --password $PASSWORD
#Press ENTER for all the questions including the incorrect IP address.

Do not be concerned by the warning messages.

# Minimal module install
amportal a ma upgrade framework
amportal a ma upgrade core
amportal a ma upgrade voicemail
amportal a ma upgrade sipsettings
amportal a ma upgrade infoservices
amportal a ma upgrade featurecodeadmin
amportal a ma upgrade logfiles
amportal a ma upgrade callrecording
amportal a ma upgrade cdr
amportal a ma upgrade dashboard

# Alternatively, install all standard modules
amportal a ma upgrade manager
amportal a ma installall
touch /etc/asterisk/manager_additional.conf
touch /etc/asterisk/manager_custom.conf
amportal restart
amportal a reload
amportal chown

If the GUI complains about the framework module or a missing /usr/sbin/amportal file try amportal a ma delete frameworkfollowed by amportal a ma upgrade framework.

Post install tasks are mandatory.

Post-install tasks

Change the webserver run user and group name to asterisk.

sed -i 's/\(APACHE_RUN_USER=\)\(.*\)/\1asterisk/g' /etc/apache2/envvars
sed -i 's/\(APACHE_RUN_GROUP=\)\(.*\)/\1asterisk/g' /etc/apache2/envvars
chown asterisk. /var/lock/apache2
service apache2 restart

Enable .htaccess files to protect sensitive webserver directories.

nano +13 /etc/apache2/sites-enabled/000-default.conf
# Add this underneath the DocumentRoot /var/www/html line
<Directory "/var/www/html">
    AllowOverride All
</Directory>

Change default “upload_max_filesize” to 20M to allow larger music on hold files.

sed -i 's/upload_max_filesize = .*/upload_max_filesize = 20M/' /etc/php5/apache2/php.ini

Set Freepbx to start on boot.

nano /etc/rc.local

Add

/usr/local/sbin/amportal start

Before exit 0 

reboot

Optional

Log File Rotation

If this is not done the log files will keep growing indefinitely.

nano /etc/logrotate.d/asterisk
/var/log/asterisk/queue_log
/var/spool/mail/asterisk
/var/log/asterisk/freepbx_debug.log
/var/log/asterisk/messages
/var/log/asterisk/event_log
/var/log/asterisk/full
/var/log/asterisk/dtmf
/var/log/asterisk/fail2ban {
        weekly
        missingok
        rotate 5
        #compress
        notifempty
        sharedscripts
        create 0640 asterisk asterisk
        postrotate
        /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null || true
        endscript
}

TFTP

If you plan to use hardware SIP phones you will probably want to enable the tftp server.

nano /etc/xinetd.d/tftp
service tftp
{
protocol        = udp
port            = 69
socket_type     = dgram
wait            = yes
user            = nobody
server          = /usr/sbin/in.tftpd
server_args     = /tftpboot
disable         = no
}

Now make the directory and restart the daemon to start tftp.

mkdir /tftpboot
chmod 777 /tftpboot
service xinetd restart

Digum addons

This is used to register digium licenses.

cd /usr/src
wget http://downloads.digium.com/pub/register/linux/register
chmod +x register
./register

To install the individual addons refer to the README files and ignore the register instructions.

Tham khảo:

http://downloads.digium.com/pub/telephony/codec_g729/README
http://downloads.digium.com/pub/telephony/res_digium_phone/README
http://downloads.digium.com/pub/telephony/fax/README
http://downloads.digium.com/pub/telephony/hpec/README

Bài liên quan
prev next