How to Install Asterisk and FreePBX on CentOS 7

Leave reply

freepbx vpsIn this tutorial we will show you how to install Asterisk and FreePBX on a CentOS 7 VPS. FreePBX is a free web based graphical user interface that controls and manages Asterisk.
Asterisk is an open source software implementation of a telephone private branch exchange (PBX) and includes many features such as: voice mail, conference calling, call recorder, automatic call distribution, interactive voice response, realtime monitoring and debugging console etc.

Let’s start the installation. Make sure your server OS is fully up-to-date:

yum clean all
yum update

Install all required packages and dependencies on your FreePBX VPS:

yum groupinstall core base "Development Tools"
yum install lynx bison php-mbstring php-pear php-gd php-xml libsepol-devel libtiff-devel openssl-devel subversion e2fsprogs-devel keyutils-libs-devel krb5-devel libogg libogg-devel libtool libtool-ltdl-devel kernel-headers kernel-devel tftp-server ncurses-devel sendmail sendmail-cf sox newt-devel libtiff-devel subversion doxygen texinfo mysql-connector-odbc unixODBC-devel sox gnutls-devel ncurses-devel net-snmp-devel neon-devel uuid-devel libuuid-devel audiofile-devel gtk2-devel speex-devel gsm-devel sqlite-devel perl-DateManip spandsp-devel freetds-devel iksemel-devel corosynclib-devel lua-devel radiusclient-ng-devel libxslt-devel portaudio-devel libical-devel gmime-devel bluez-libs-devel jack-audio-connection-kit-devel libedit-devel jansson-devel libsrtp-devel

Install pjproject

cd /opt 
git clone git://github.com/asterisk/pjproject pjproject 
cd pjproject/ 
./configure --libdir=/usr/lib64 --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr
make dep 
make 
make install 
ldconfig

Install SRTP

cd /opt  
wget http://srtp.sourceforge.net/srtp-1.4.2.tgz 
tar zxvf srtp-1.4.2.tgz
cd srtp 
autoconf 
./configure CFLAGS=-fPIC --prefix=/usr  
make 
make runtest
make install
ldconfig

Install jansson

cd /opt 
wget http://www.digip.org/jansson/releases/jansson-2.7.tar.gz
tar zvxf jansson-2.7.tar.gz 
cd jansson-2.7
autoreconf -i
./configure --prefix=/usr/ --libdir=/usr/lib64
make  
make install 
ldconfig

Install Lame

cd /opt 
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar zxvf lame-3.99.5.tar.gz 
cd lame-3.99.5
./configure 
make 
make install

Install Asterisk

Add a new user named ‘asterisk’:

adduser asterisk -M -c "Asterisk User"
cd /opt
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13.7.2.tar.gz
tar zxvf asterisk-13.7.2.tar.gz
cd asterisk-13.7.2
contrib/scripts/install_prereq install
./configure --libdir=/usr/lib64
contrib/scripts/get_mp3_source.sh
make menuselect

Choose which modules to build, select ‘Save & Exit’ and continue with the installation:

make 
make install 
make config 
ldconfig
chkconfig asterisk off

Set permissions of certain files and directories related to Asterisk:

chown asterisk. /var/run/asterisk
chown asterisk. -R /etc/asterisk
chown asterisk. -R /var/{lib,log,spool}/asterisk
chown asterisk. -R /usr/lib64/asterisk
chown asterisk. -R /var/www/

Edit the PHP configuration file and set the upload_max_size value to 128 MB or higher.

vi /etc/php.ini
upload_max_filesize = 128M

Edit the main Apache configuration file (/etc/httpd/conf/httpd.conf) and change user and group from ‘apache’ to ‘asterisk’. Also, change ‘AllowOverride None’ directive to ‘AllowOverride All’.
Restart the Apache web server for the changes to take effect:

systemctl restart httpd.service

Log in to the MariaDB server using the ‘root’ user login credentials and create new user and two databases:

mysql -u root -p
MariaDB [(none)]> CREATE DATABASE asterisk;
MariaDB [(none)]> CREATE DATABASE asteriskcdrdb;
MariaDB [(none)]> CREATE USER 'asterisk'@'localhost' IDENTIFIED BY 'Y0uR-PASSW0RD';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON asterisk.* TO 'asterisk'@'localhost';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON asteriskcrddb.* TO 'asterisk'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit;

Do not forget to replace ‘Y0uR-PASSW0RD’ with a strong password.

Install Freepbx

pear install db-1.7.14
pear install Console_Getopt
cd /opt
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-13.0-latest.tgz
tar zxvf freepbx-13.0-latest.tgz 
cd freepbx 
./start_asterisk start 
./install
Database engine [mysql]: <Enter>
Database name [asterisk]: <Enter>
CDR Database name [asteriskcdrdb]: <Enter>
Database username [root]: asterisk
Database password: Y0uR-PASSW0RD
File owner user [asterisk]: <Enter>
File owner group [asterisk]: <Enter>
Filesystem location from which FreePBX files will be served [/var/www/html]: <Enter>
Filesystem location from which Asterisk configuration files will be served [/etc/asterisk]: <Enter>
Filesystem location for Asterisk modules [/usr/lib64/asterisk/modules]: <Enter>
Filesystem location for Asterisk lib files [/var/lib/asterisk]: <Enter>
Filesystem location for Asterisk agi files [/var/lib/asterisk/agi-bin]: <Enter>
Location of the Asterisk spool directory [/var/spool/asterisk]: <Enter>
Location of the Asterisk run directory [/var/run/asterisk]: <Enter>
Location of the Asterisk log files [/var/log/asterisk]: <Enter>
Location of the FreePBX command line scripts [/var/lib/asterisk/bin]: <Enter>
Location of the FreePBX (root) command line scripts [/usr/sbin]: <Enter>
Location of the Apache cgi-bin executables [/var/www/cgi-bin]: <Enter>
Directory for FreePBX html5 playback files [/var/lib/asterisk/playback]: <Enter>

Create a systemd startup script for FreePBX:

vi /etc/systemd/system/freepbx.service

add the following lines:

[Unit]
Description=FreePBX VoIP Server
After=mariadb.service
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start
ExecStop=/usr/sbin/fwconsole stop
 
[Install]
WantedBy=multi-user.target

Set the FreePBX service to start on boot and start FreePBX:

systemctl enable freepbx.service
systemctl start freepbx

Enable log file rotation:

vi /etc/logrotate.d/asterisk

add the following lines:

/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 {
        weekly
        missingok
        rotate 5
        notifempty
        sharedscripts
        create 0640 asterisk asterisk
        postrotate
        /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null || true
        endscript
}

Open up your favorite web browser, navigate to  http://<FreePBX-Server-IP-Address>/admin and create a new administrator user.

freepbx vps back-end

That is it. The Asterisk and FreePBX installation is complete.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Asterisk and FreePBX for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.


50% OFF Coupon

EXCLUSIVE EMAIL UPDATES AND “MEMBERS-ONLY” CONTENT


9 Responses to “How to Install Asterisk and FreePBX on CentOS 7”

  1. KLR

    This is going to sound stupid and ignorant, but here it goes. I have heard a lot about Asterisk, have seen a few tutorials on how to install it – but I have no clue on how to use it, once installed. Also, what else do I need, besides the software itself? Do I need a telephone line, or just an Internet connection will do?

    Reply
  2. LogisQuebec.com

    Great article. Thank you

    Reply
  3. George

    Location of the Apache cgi-bin executables [/var/www/cgi-bin]:
    Directory for FreePBX html5 playback files [/var/lib/asterisk/playback]:
    after making this I am getting ” Error!
    Invalid Database Permissions. The error was: could not find driver” <- this… what's the problem?

    Reply
  4. RB

    Your guide is unfortunately broken and assumes various things ( ie apache already installed, mysql already installed and setup, missing -y on yum )

    Why not just make this into an install script and be done with it? The work is 90% there.

    You also end up with loads of permissions errors following it literally line for line.

    In Apache log:

    PHP Fatal error: Class ‘FreePBX’ not found in /var/www/html/admin/config.php on line 130

    Time to look over and fix this guys, virtually unusable in its current state. Particularly for those of little Linux knowledge.

    Reply
  5. Fahad Snafee

    Thanks for this! followed everything that’s written here and it works 100%

    Reply
  6. Sung

    I’m getting “Failed to execute operation: Bad message” when running “systemctl enable freepbx.service” The service would start with the command “systemctl start freepbx” but I cannot enable. Please help

    Reply
    • admin

      Please make sure that your systemd startup script for FreePBX is the same as in the tutorial. If you still experience the same problem you can run ‘journalctl -xe’ for more information about the problem. Thanks.

      Reply

Leave a Reply