FreePBX on Gentoo, Why?
As the community of Gentoo users are very dedicated and love to understand far more than is necessary, how does FreePBX blend into that school of thought? FreePBX is a “simple” way to configure asterisk. It seems that the users in the gentoo community are more apt to learn the dial plan for themselves and call it a day. I think that is why a few years ago when I started the asterisk adventure I couldn’t find a nice document that outlines the install process. I’m also going to attribute this to a much less popular FreePBX in those days. The question here is, “Why would someone want to install FreePBX on Gentoo, when in a matter of an hour, instead of a few, you could be up and running with TrixBox or some other RPM based distro that uses RedHat conventions?” The answer, usually, is that you just can’t live outside of Gentoo again. I know, after learning Gentoo, I find it nearly impossible to be satisfied with a binary based distro anymore. I love the fact that I have to know and work with every package on my system. It forces my attention to detail and ultimately makes a very secure box! I end up with a very complete understanding of the workings of all the software on my system. The most important points about Gentoo are SECURITY and RELABILITY! I’ve had Gentoo installs running for over a year without a reboot. They “just work.” With very minimal extra effort I can prevent almost all hacking on my public Internet facing boxes!
Gentoo Lovers, Read ON!
Can I sum up my religious following of Gentoo as my only preferred Linux platform in one word? Yes, ELEGANT! The more I use the platform the more I feel that the Gentoo community solves the problems of the Linux platform world with well thought out, well designed, and very elegant solutions.
To eBuild or not to eBuild
In the world of Gentoo either there is a nice and easy eBuild or one doesn’t exist yet. It is not too often that I run across packages that don’t provide an eBuild but, in the case of FreePBX, I did. As I mentioned earlier, I wasn’t too surprised. With no eBuild, you have an already running, fully functional, environment to compile whatever you find. You do, however, have to zero in a few things to make sure you’re environment is going to support your installation correctly. We need to check our make flags and also emerge any dependant programs and libraries.
Asterisk eBuild … A Little Dated
The first step in a sold FreePBX installation is the asterisk install that powers it. Unfortunately the eBuild for asterisk is a little dated. It’s at version 1.2.27. For my installation I’m going to go with version 1.4.18.1. I’m sticking with that version because of a DTMF duplicate digit bug that seems to pop up after that version. I’m afraid I don’t have a reference to the url but I got my info from voicepulse support. I have to say that I’m not sure if it has been fixed by now but I know from use that this version seems to work well.
Before We Get There, It’s Dependency Time!
Since we’re compiling our own asterisk we’re going to need to do some of our own dependency compiles. We’ll also be able to get away with adding some extra make flags and using a few eBuilds. I’m writing my tutorial from the point of view of a strictly sip user. I’m not making use of any hardware or iax, just sip. Bearing our goals in mind the only dependency we’re going to need to compile is the zaptel driver. Strictly speaking, we don’t need zaptel for sip to function but, if we want music on hold or conference calling, we’re going to need the ztdummy module. Ztdummy is a software based timing driver. I’m going to leave the explanation at that for this article.
Zaptel Install
For my own compiles I tend to use /usr/src for my work.
cd /usr/src
wget http://downloads.digium.com/pub/zaptel/zaptel-1.4.12.1.tar.gz
tar xzf zaptel-1.4.12.1.tar.gz
./configure
make menuconfig
Configure as desired then
make
Before we continue on we need to make sure that we have gentoo-sources installed (or any other flavor of kernel sources you’ve used for your system). If you’re a genkernel user you may need to take a few extra steps here.
emerge gentoo-sources
Another side note … you must have CRC-CCITT functions enabled in your kernel for this to work. It’s in the last sub menu of the kernel config menu. In your .config file it will look like this:
CONFIG_CRC_CCITT=y
You’ll know that you missed this if you see this when you try a make install:
WARNING: "crc_ccitt_table" [/usr/src/zaptel-1.4.11/kernel/zaptel.ko] undefined!
Time to run the zaptel install.
make install
Almost there but we need to make sure Gentoo auto loads the ztdummy module.
echo ztdummy >> /etc/modules.autoload.d/kernel-2.6
Let’s get the init script for zaptel setup
make config
This is “almost” Gentoo drop in. We have to make a small change on line 40:
functions needs to be changed to functions.sh
If you miss this step you’ll end up with:
init.d/zaptel: line 40: /etc/init.d/functions: No such file or directory
Lookn’ good! Let’s get some other Asterisk pre-reques installed.
Some eBuilds With A Touch of Make.conf
In order to have access to all the functions of asterisk we’re going to need to install some eBuilds. It looks like I’m not going to have enough time to just pull out the make variables that just pertain to asterisk so I’m going to give you a picture of all you’re going to need for your make.conf for both asterisk and FreePBX in this step. Here’s what you need:
alsa mmx mysql uclibc vmdbmysql speex resperl apache2 cli pcre xml zlib posix session simplexml soap sockets spl ssl tokenizer truetype unicode xml xmlreader xmlwriter xsl zlib ncurses curl perl php rtc -X sse ctype tetex libwww
You’ll notice I left off the zaptel and libpri use flags. This is becuase we’re using our own compiled version of zaptel and I don’t want emerge to pick up the dated eBuild as a dependency.
The next set of installs is going to support using the ogg/vorbis file format inside of asterisk. You can abbreviate this list by just an emerge vorbis-tools with the set of make flags I have listed about this. Here’s the full package list that will be installed:
media-sound/alsa-headers
media-libs/libogg
media-libs/libvorbis
media-libs/alsa-lib
media-libs/libao
media-sound/vorbis-tools
media-libs/speex
With all of these installed we should be able to continue our journey on to the Asterisk compile.
Asterisk Install
Finally on to the good stuff. Let’s get our feet wet with our Asterisk install. For my own compiles I tend to use /usr/src for my work.
cd /usr/src
wget http://downloads.digium.com/pub/asterisk/releases/asterisk-1.4.18.tar.gz
tar xzf asterisk-1.4.18.tar.gz
cd asterisk-1.4.18
./configure
make menuconfig
Configure as desired then
make
make install
One Small Step For This Tutorial, One Giant Step Toward FreePBX
Now that we’ve got the most complicated compiling part of this setup working we can pat ourselves on the back and move onto easier jobs!
FreePBX Required eBuilds
Before emerging be sure to read the earlier section on my make.conf flags!
We’re going to need:
dev-db/mysql
dev-lang/perl
dev-perl/DBD-mysql
dev-perl/DBI
dev-perl/libxml-perl
media-sound/lame
media-sound/mpg123
media-sound/sox
net-misc/curl
net-misc/openssh
www-servers/apache
Emerge away, nothing here should present any problems.
Asterisk Addons Install
FreePBX makes use of several features from the asterisk-addons package. Since we don’t have an up to date ebuild for this we’re going to have to go back to a compile.
cd /usr/src
wget http://downloads.digium.com/pub/asterisk/releases/asterisk-addons-1.4.7.tar.gz
tar xzf asterisk-addons-1.4.7.tar.gz
cd asterisk-addons-1.4.7
make menuconfig
Configure as desired then
make
make install
Gentoo Config Updates
Now that we have all of our software in place its time to make some configuration changes to our environment to support FreePBX. I’m coming from the point of a fresh Gentoo install. If your system has been “lived in” these changes may be more subjective.
Apache
This change is a bit dated now as this is asked in the FreePBX install script but it will at least let us take the default for it. A stock apache install of Gentoo puts the document root at /var/www/localhost/htdocs whereas RedHat conventions place it at /var/www/html. FreePBX is expecting this convention so we’re going to use a symlink to minimize config changes.
ln -s /var/www/localhost/htdocs/ /var/www/html
Next step is to make apache run itself as the user and group of asterisk. Unfortunately I don’t think FreePBX has eliminated this shortcoming yet.
In /etc/apache2/httpd.conf: The owning user and group of the running apache server needs to be changed to asterisk – (around line 136)
"User apache" needs to be changed to "User asterisk"
"Group apache" needs to be changed to "Group asterisk"
PHP
We need to make a few changes to /etc/php/apache2-php5/php.ini:
around line 445: "magic_quotes_gpc = On" needs to be changed to "magic_quotes_gpc = Off"
around line 552: "upload_max_filesize = 2M" needs to be changed to "upload_max_filesize = 20M"
around line 560: "allow_url_fopen = Off" needs to be changed to "allow_url_fopen = On"
FreePBX, We’re There!
With all of our prep work done the rest should go smoothly.
Download and extract FreePBX:
cd /usr/src
wget http://internap.dl.sourceforge.net/sourceforge/amportal/freepbx-2.5.1.tar.gz
tar xzf freepbx-2.5.1.tar.gz
Just a Few More Steps
Next we have to setup MySQL. If this is a fresh install of Gentoo you need to run:
/usr/bin/mysql_install_db
This will initialize the database for the first time.
Start MySQL
/etc/init.d/mysql start
Add CDR tables
mysqladmin -u root password 'db_root_pwd'
mysqladmin create asteriskcdrdb -p
mysql --user=root --password=db_root_pwd asteriskcdrdb < /usr/src/freepbx<version>/SQL/cdr_mysql_table.sql
Add freepbx tables
mysqladmin create asterisk -p
mysql --user root -p asterisk < /usr/src/freepbx<version>/SQL/newinstall.sql
Grant access to these two databases you just created
Note the default mysql username/password is asteriskuser/amp109.
If you change either of these, you will be prompted for them while running ./install below
mysql --user root -p
mysql> GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Now that we have mysql setup we can get asterisk running and ready for the FreePBX install script. Execute these commands:
cd /usr/src/freepbx<version>
asterisk
./start_asterisk start
killall asterisk
./start_asterisk start
We have to start and stop a few times because of lack of configuration files I believe. This was a little trial and error for me. Going through this on a system where a ./start_asterisk start just works won’t hurt anything.
FreePBX Anyone?
Finally ready to run the install script. Let ‘em rip:
./install_amp
The questions in the installer script should be clearly answered in the rest of this article.
Start up Apache:
/etc/init.d/apache start [or restart if you had it running]
Point your browser to the IP of the box you set this up on and you should have FreePBX!!
Boot Proof The Setup
If you want everything to come up when the system boots you’ll have to run a few commands:
rc-update add apache default
rc-update add mysql default
echo “/usr/local/sbin/amportal start” >> /etc/conf.d/local.start
Conclusions
I enjoyed writing this article. I hope this article will help to deploy Asterisk and FreePBX in Gentoo. I tend to get a bit verbose. Believe it or not, I did leave out some details in this article. If you get stuck feel free to contact me for help. You can also comment on this article for pointers as well.
I understand this is probably better served in a Wiki. I will eventually get it into one but for now all I have is my blog.













Gentoo Way!
for new asterisk versions install layman’s “voip” overlay:
[I] net-misc/asterisk
Available versions: 1.2.27 {M}(~)1.4.21.2[1] {M}(~)1.4.22-r1[1] {M}(~)1.6.0[1] {alsa bri caps curl dahdi debug doc elibc_uclibc freetds gtk h323 hardened iconv imap jabber kde keepsrc ldap lowmem misdn mmx mysql newt nosamples odbc osp oss pic postgres pri qt3 radius snmp speex sqlite ssl static vorbis zaptel}
Installed versions: 1.6.0[1](23:43:26 14.10.2008)(alsa caps curl iconv imap ldap mmx snmp speex ssl vorbis -dahdi -debug -freetds -h323 -jabber -keepsrc -misdn -newt -nosamples -odbc -oss -pic -postgres -radius -sqlite -static)
Homepage: http://www.asterisk.org/
Description: Asterisk: A Modular Open Source PBX System
[1] “voip” /usr/portage/local/layman/voip
and in next time use eix for search in not installed overlays
hey man
thanks for the guide, much appreciated u using your time
elvis
Thank you! I used your guide to build Asterisk+FreePBX on a gentoo-mips system.
I’m glad to hear you were able to find this useful.
I’m curious … if you don’t mind me asking -
Was it an exiting small footprint appliance when you were done?
How was the quality on the MIPS system after you finished?
How fast was the processor?
Did you you get music on hold or conference rooms working?
Hey there
I have this running in a vhost environment and am running it with mpm-itk. Compile Apache with the mpm-itk module, and place the following into the vhost config:
AssignUserId asterisk asterisk
In Gentoo, you can add the following to make.conf:
APACHE2_MPMS=”itk”
You should add a user declaration like above to every other vhost on the server, as I’m not sure at the moment if there is a default user for itk.
Does anyone know if will work with Gentoo 10?
I am trying to run skype and siptosis