Hi all! If you'd like to bring the power of VoIP systems to your SOHO, here's all you need! This TKLPatch will convert Turnkey Core 10.04 beta to a powerfull Asterisk system with FreePBX installed. I'm giving my first steps on this world of telephony over ip, so as allways, this patch surely needs a lot of test. FreePBX is like a child, it starts nicely and then begin to complain about a lots of things, but I was able to stabilize the installation so that it's happy and without complains! If there's someone in the community with is more experienced with asterisk, please be kind to install and test this one.
Asterisk 1.6 installed from ubuntu's repos.
Upgraded default freePBX installed modules to last versions.
http and https access configured.
Secured admin interface using database authentication (user: admin, pass: admin)
1. Set Hostname to asterisk
echo "$HOSTNAME" > /etc/hostname
sed -i "s|127.0.1.1 \(.*\)|127.0.1.1 $HOSTNAME|" /etc/hosts
2. Add sources of universe repository (for asterisk-addons sources)
echo deb-src http://archive.ubuntu.com/ubuntu lucid universe >> /etc/apt/sources.list.d/sources.list
3. Install required packages. I installed makepasswd to create the initial random passwords. Sox and mpg123 are for audio convertion in the recording system.
install apache2 php5 mysql-server php5-mysql php5-cli php-pear php-db makepasswd asterisk sox ssl-cert asterisk-sounds-extra mpg123
apt-get -y build-dep asterisk-addons
apt-get -b source asterisk-addons
dpkg -i *.deb
5. Change apache user and group to asterisk to prevent ownership and permissions conflicts between asterisk and freepbx. FreePBX does a bunch of chmods and chown that causes conflicts with asterisk. To fix this, this is the approach I felt was easy/stable to apply for this patch.
sed -i "s/www-data/asterisk/" /etc/apache2/envvars
6. Get freePBX.
tar xzf freepbx-2.8.0.tar.gz
7. Create mysql database for freepbx and asteriskcdr
mysqladmin -u root create asterisk
mysqladmin -u root create asteriskcdrdb
mysql -u root asterisk < SQL/newinstall.sql
mysql -u root asteriskcdrdb < SQL/cdr_mysql_table.sql
mysql -u root <<-END_PRIVS
GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY "amp109";
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY "amp109";
8. Increase maximum allowed size for uploaded files in php. This is to be able to upload bigger music files for the Music On Hold feature.
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php5/apache2/php.ini
9. Backup asterisk modules settings as freePBX mess them up. If you don't backup this settings, when freePBX overrides them, your asterisk won't start anymore. They are restored after freePBX installation.
cp /etc/asterisk/modules.conf /etc/asterisk/modules.conf.bak
10. Installation of freePBX fails with the error "PHP Fatal error: Cannot redeclare __parse_DialRulesFile()" in the step "Upgrading to 2.8.0alpha2..". Solution would be edit the source files OR run installation again to continue. I took the second approach and it works flawlessly. More info here
. amportal.conf is being overlayed.
# Initial run of installation
# Second run to bypass the Cannot redeclare __parse_DialRulesFile() error
if [ $? = 255 ]; then
echo "Second run..."
11. Restore asterisk modules settings. I want Asterisk to startup!
cp /etc/asterisk/modules.conf.bak /etc/asterisk/modules.conf
12. Final symlinks and permissions needed. The sip_notify link prevents freePBX of complain that it can't create that link because the file is already there. I kept the original as a backup measure. The mohmp3 -> moh is beacause the music on hold module expects to save the files in mohmp3 but the directory by deafult is moh. The agi-bin directory prevents freePBX to complain it can't copy files there. There's another agi-bin in the system where modern modules install things but there's still the need to keep this folder. More info: google. (Sorry I lost the url) Everything else is permissions related.
mv /etc/asterisk/sip_notify.conf /etc/asterisk/sip_notify.conf.bak
ln -s /var/www/admin/modules/core/etc/sip_notify.conf /etc/asterisk/
ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3
mkdir -p /var/lib/asterisk/agi-bin
chown -R asterisk:asterisk /var/www
chown -R asterisk:asterisk /var/lib/asterisk
chown -R asterisk:asterisk /etc/asterisk
chown -R asterisk:asterisk /usr/share/asterisk
chown asterisk:asterisk /etc/amportal.conf
13. Upgrade modules: The first thing that freePBX tells you is to upgrade your modules, so I just wanted to avoid this step to final users at least when you just install your appliance.
14. Set amportal to start on system boot. Clear enough. This needs to run when the system starts.
sed -i -e "s/^\(exit 0\)$/\/usr\/local\/sbin\/amportal start\n\1\n/" /etc/rc.local
15. Set amportal to control asterisk service. If you don't, the amportal script won't be able to stop and start asterisk and you won't be able to do it from the gui niether. So I remove it from startup and let amportal manage that service. The change in background is necesary for debian systems.
update-rc.d -f asterisk remove
sed -i "s/BACKGROUND=0/BACKGROUND=1/" /usr/sbin/safe_asterisk
16. Final touches: configure apache's sites, ssl, etc.
service apache2 stop
service mysql stop
17. Clean apt cache and sources
rm -Rf /usr/src/
mkdir -p /usr/src
Also, there are some issues regarding Voicemail. It seems they are aware of those too. FreePBX has it flaws here and there. If you find something that is not working as expected, please post here a message and I'll research what's happening. Or better: propose a solution (and don't forget to add the sources of the info!) ;)