Tuesday, December 4, 2012

Quick and Dirty Asterisk 11 and FreePBX 2.11 (RC) installation guide

[UPDATE 11-09-2013 – FREEPBX 2.11 FULL RELEASE]
MORE UPDATE : Why not try our VMWare Image of Asterisk 11 and FBX2.11B2, no installation required! Fully functional and business ready.
Hi guys, been a while since I got my hands on the blogging software. Anyway, I would like to share a simple guide to get an Asterisk 11 and FreePBX 2.11 (full release) running on a Debian 6.0x OS. If you use other OSes, the only thing you will probably change is the software repo manager (debians use apt, centos will like use yum) and the packages name. It won’t run too far from the installation shown here. Here’s a quick guide to install to Ubuntu (close to debian installation) and CentOS.
NOTES
  • You should use FreePBX 2.11 as it officially supports Asterisk 11. Other versions may work but things may also break
  • This is a step by step copy paste guide, no explanations are provided. If anything breaks, something is wrong, nothing should break actually
  • # means it’s a command line you need to copy paste.  Of course, don’t copy the # itself, its just an indicator that it’s shell command …
  • Some of the Asterisk installations steps are taken off http://blogs.digium.com (don’t have to reinvent the wheel..)
  • This is not a comprehensive installation with best practices etc, but it does take care of some basic security stuff, do read online as much as possible
  • Get your Debian installed and ready to get worked on, be sure to work on a putty.exe session so be sure to install ssh # apt-get install ssh
  1. # apt-get update && apt-get upgrade    (reboot the box if updates are installed, if clean install no need to reboot)
  2. # apt-get install --force-yes build-essential ssh sudo libxml2 libxml2-dev libtiff4 libtiff4-dev php5 libapache2-mod-php5 php5-cli php5-curl php5-mysql php5-gd libmysqlclient-dev php-pear php-db linux-headers-`uname -r` curl sox apache2 libssl-dev libncurses5-dev bison libaudiofile-dev subversion libnewt-dev libcurl4-openssl-dev libnet-ssleay-perl openssl libauthen-pam-perl libio-pty-perl vim tcpdump  htop php5-cgi mpg123 libdbd-mysql-perl libdbi-perl libhtml-template-perl libnet-daemon-perl libplrpc-perl libterm-readkey-perl mysql-client-5.1 mysql-common libapt-pkg-perl libsqlite3-dev uuid-dev -y   (These include dependencies for FreePBX as well and some extras)
  3. # reboot (yes, reboot, then login to continue from below)
  4. # cd /usr/src/
  5. # wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz 
  6. # wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz 
  7. # wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
  8. # tar -zxvf dahdi-linux-complete-current.tar.gz
  9. # tar -zxvf libpri-1.4-current.tar.gz
  10. # tar -zxvf asterisk-11-current.tar.gz
  11. # cd dahdi-*
  12. # make && make install && make config
  13. # cd ..
  14. # cd libpri-*
  15. # make && make install    (if you face errors with esp Ubuntu, you need to get a patch here, you should not see any errors tho)
  16. Before we install Asterisk, we would like to prep it for FreePBX use, e.g. creating groups and users and associating Apache to run as that low privileged user, dependencies etc, etc..
    • # groupadd asterisk
    • # useradd -g asterisk -c "Asterisk PBX" -d /var/lib/asterisk asterisk
    • # mkdir /var/run/asterisk
    • # chown -R asterisk:asterisk /var/run/asterisk
    • # cd /etc/apache2  (now, we will attempt to modify apache configs to run as the new user/group asterisk we just created, steps may be different from other OSes, take note)
    • # mv envvars envvars.old
    • # echo "export APACHE_RUN_USER=asterisk" >> envvars
    • # echo "export APACHE_RUN_GROUP=asterisk" >> envvars
    • # echo "export APACHE_PID_FILE=/var/run/apache2.pid" >> envvars
    • # echo "export APACHE_RUN_DIR=/etc/apache2" >> envvars
    • # echo "export APACHE_LOG_DIR=/var/log/apache2" >> envvars
    • # chown -R asterisk:asterisk /var/lib/php5
    • # /etc/init.d/apache2 restart
  17. # cd ..
  18. # cd /usr/src/asterisk-11*
  19. # contrib/scripts/get_mp3_source.sh
  20. # ./configure && make menuconfig (when the menu pops up, be sure to select under Add-ons, format_mp3, res_config_mysql, app_mysql, app_saycountpl and cdr_mysql. Now, go to Extra Sound Packages and if you can’t see that left menu option just keep scrolling down using your down arrow key, when you found it, move over to the right menu then select Extra-Sounds-En-WAV, in core sound packages, also select the WAV version for best compatibility. Save and exit) 
  21. # make && make install && make samples (NOTE: Don’t need to make config since we are using FreePBX and we start amportal rather than just asterisk itself)
  22. At this point you have a running Asterisk server! Congrats, now comes FreePBX. But there’s not much configs, so be prepared for Asterisk complaining about stuff and all if you try to start it.
  23. apt-get install -y mysql-server (when prompted, create the MySQL password, for this guide, we will use my@sql as the password
  24. cd /usr/src
  25. wget http://mirror.freepbx.org/freepbx-2.11.0.tar.gz (replace appropriate version that’s newer when available, see here )
  26. tar -zxvf freepbx*
  27. # cd freepbx*
  28. # mysqladmin create asteriskcdrdb -h localhost -u root -p (Enter your MySQL password as above when prompted)
  29. mysql -u root -p asteriskcdrdb < /usr/src/freepbx-2.11.0/SQL/cdr_mysql_table.sql (Enter your MySQL password when prompted, also note the directory of FreePBX to match the ver you downloaded)
  30. mysqladmin create asterisk -h localhost -u root -p (Enter your MySQL password as above when prompted)
  31. mysql -u root -p asterisk < /usr/src/freepbx-2.11.0/SQL/newinstall.sql (Password again)
  32. # mysql -h localhost -u root -p  mysql --execute="GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'fbx@mysql';" (Note: Here we create a new user for FreePBX to use MySQL and that is user asteriskuser with password fbx@mysql, change accordingly)
  33. mysql -h localhost -u root -p  mysql --execute="GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'fbx@mysql';"
  34. # cd /usr/src/freepbx-2.11.0/
  35. # mysql -h localhost -u root -p mysql --execute="FLUSH PRIVILEGES"
  36. # asterisk && ./install_amp (AT THIS POINT, ONLY ENTER THE DATABASE PASSWORD YOU CREATED IN STEP 34, in the case above that would be fbx@mysql)
  37. # /var/lib/asterisk/bin/module_admin upgradeall
  38. # /var/lib/asterisk/bin/module_admin reload
  39. Now to sign on to FreePBX. Go to your server http://<ipaddress>/html, default username and password is admin/admin be sure to change that too!!!
  40. Immediately update all modules in module admin
  41. NOTE: If you see FreePBX complain about some symlinks, do this below rm /etc/asterisk/iax.conf
    rm /etc/asterisk/sip.conf
    rm /etc/asterisk/extensions.conf
    rm /etc/asterisk/logger.conf
    rm /etc/asterisk/features.conf
    rm /etc/asterisk/sip_notify.conf
    rm /etc/asterisk/confbridge.conf
    rm /etc/asterisk/ccss.conf
    rm /etc/asterisk/cel.conf
    rm /etc/asterisk/cel_odbc.conf
    rm /etc/asterisk/res_odbc.conf
    /var/lib/asterisk/bin/retrieve_conf

    • Then refresh your FreePBX browser page, and hit Apply Conf. If there are other .conf files interfering, just rm it and retrieve_conf again….
  42. VERY IMPORTANT TO DO THIS NOW!!!
    • Change the admin password | Go to Admin | Administrators, select admin and change the password there
    • Change your AMI password – Go to Settings | Advanced Setting | under Asterisk Manager, change it there to something of your choice
    • Change ARI password – Go to Settings | Advanced Settings | under System Settings, change User Portal Admin Password to something of your choice
    • Get all the latest packages – Go to Admin | Module Admin |  select Basic and Extended, click on download all, upgrade all, click process, wait to download, click Apply
    • Sometimes, the SIP Nat settings can be wrong, click on Advanced | Asterisk SIP Settings | Be sure to set to Public to get things started..
    • If you get errors with conference just ignore or clear it, it wont come back and conferencing will work just fine
    • You should not screen any significant errors or warnings in the Dashboard
  43. OPTIONALLY, if you want Asterisk to start automatically when reboot
  44. Create a FreePBX startup script
  45. # echo “#!/bin/bash” > /usr/bin/amportal-start
    # echo “/usr/local/sbin/amportal start” >> /usr/bin/amportal-start
    # echo “exit 0” >> /usr/bin/amportal-start
    # chmod +x /usr/bin/amportal-start

  46. # nano /etc/rc.local
  47. Before where it says exit 0, paste this line
    # /usr/bin/amportal-start
  48. Reboot at least once
  49. And there you go, functional FreePBX 2.11 with Asterisk 11 ready to go…
  50. Test, test and test more

Known issues (this list keeps getting updated!)

- You might get errors with the FreePBX UI not loading and what not and says server error, tail the apache error log, its likely some module like digium modules breaking it, if you get that, run this

# amportal a ma disable digiumaddoninstaller
# amportal a ma delete digium_phones
# amportal a ma delete digiumaddoninstaller

You can add them later using Module Admin

Thanks and have a great week ahead!
Sanjay

Post a Comment