Recently I needed to install Asterisk with FreePBX on an existing Ubuntu 10.04 LTS (Lucid Lynx) 64 bit server.  Since Asterisk is really targeted at CentOS this was a bit of a challenge, especially as FreePBX isn’t really designed to be installed as a standalone anymore.  However with a little research and quite a bit of fiddling I managed to get Asterisk up and running with FreePBX on Ubuntu server.

Installing Asterisk

Previously the Asterisk packages available for Ubuntu were either simply not available or flat out didn’t work.  However, Asterisk now has pre-built binary packages available for Ubuntu that can be installed from either their repository using apt or via direct download.

I chose to add the repository and install using apt:

sudo apt-key adv --keyserver --recv-keys 175E41DF
sudo add-apt-repository "deb `lsb_release -cs` main"
sudo add-apt-repository "deb-src `lsb_release -cs` main"
sudo apt-get update

The Asterisk package also depends on a Python package, so that needs to be installed as well.  As a side effect, the Asterisk package also creates the Ubuntu user and group asterisk.

FreePBX requires Apache, MySQL and PHP, which this server already had in place.  However since FreePBX should be run under the asterisk user, the regular apache binary needed to be replaced with the MPM (multi-processing module) to allow different virtual hosts to run under different users.  Also, the install script for FreePBX is PHP and so requires the command-line PHP interpreter to be installed.

sudo apt-get install python-software-properties asterisk-1.8 asterisk-mysql apache2-mpm-itk php5-cli php-db

Asterisk should now be running on your system.  You can verify this in the shell:

sudo asterisk -rx "core show version"
Asterisk built by pbuilder @ nighthawk on a x86_64 running Linux on 2012-04-03 13:58:20 UTC

Installing FreePBX

First I downloaded FreePBX and extracted it:

sudo tar xf freepbx-2.9.0.tar.gz -C /usr/src
cd /usr/src/freepbx-2.9.0

Configuring Apache

I chose to run FreePBX on a non-standard port 8100, for security reasons.  To enable Apache to listen on port 8100, I edited /etc/apache2/ports.conf as root and added the line Listen 8100 after Listen 80:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80
Listen 8100

I created a DNS entry for the subdomain to host FreePBX, and added /home/www/freepbx to host the FreePBX files.  I also opted for a separate Apache error log for the FreePBX site.  The resulting site configuration file /etc/apache2/sites-available/ looked like this:

<VirtualHost *:8100>
	ServerAdmin     it @
	DirectoryIndex  index.html index.php
	DocumentRoot    /home/www/freepbx

	<IfModule mpm_itk_module>
		AssignUserId asterisk asterisk

        <Directory /home/www/freepbx>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from All

        ErrorLog /var/log/apache2/freepbx-error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined

Finally, I made the site available:

sudo a2ensite
sudo service apache2 reload

Configuring MySQL

FreePBX requires a couple of databases to store Asterisk configuration data and call detail records, and should have it’s own MySQL user available to manage those databases.  I used the command line MySQL client to create and populate the databases and tables, but using phpMyAdmin would work just as well.

Creating databases:

mysql -u root -p
Enter password: <my root user password>

mysql> create database asterisk;
Query OK, 1 row affected (0.00 sec)

mysql> create database asteriskcdrdb;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on asterisk.* to freepbx@localhost identified by '<a strong password>';
Query OK, 0 rows affected (0.04 sec)

mysql> grant all on asteriskcdrdb.* to freepbx@localhost identified by '<a strong password>';
Query OK, 0 rows affected (0.00 sec)

Creating the tables and populating them (make sure you are in :

mysql -p -u freepbx asterisk < /usr/src/freepbx-2.9.0/SQL/newinstall.sql
Enter password: <the newly created freepbx user's password>

mysql -p -u freepbx asteriskcdrdb < /usr/src/freepbx-2.9.0/SQL/cdr_mysql_table.sql
Enter password: <the newly created freepbx user's password>

Running the FreePBX Install Script

This is the part that caused me no end of pain due to the fact that the Asterisk package and the FreePBX script are maintained by two different entities.  The installation script needs to be run as root and changes various Asterisk config files.  However by default those config files can only be edited by the asterisk user or a member of the asterisk group.  I solved this by making root a member of the asterisk group and then running the installation script.

Also, despite asking for the base directory for web files there seem to be some places where /var/www/html is hard coded.  To work around that, I created a symlink to my FreePBX files directory.

sudo usermod -a -G asterisk root
sudo ln -s /home/www/freepbx /var/www/html
sudo ./install_amp

The installer will ask you for a bunch of configuration information:

Enter your USERNAME to connect to the ‘asterisk’ database:[asteriskuser] freepbx
Enter your PASSWORD to connect to the ‘asterisk’ database:[amp109] <the newly created freepbx user’s password>
Enter the hostname of the ‘asterisk’ database:[localhost] (I just hit ENTER to accept the default of localhost)
Enter a USERNAME to connect to the Asterisk Manager interface:[admin] freepbxadmin
(for security reasons I changed this from the default)
Enter a PASSWORD to connect to the Asterisk Manager interface:[amp111] <a strong password for freepbxadmin>
Enter the path to use for your AMP web root:[/var/www/html] /home/www/freepbx
Enter the IP ADDRESS or hostname used to access the AMP web-admin[xx.xx.xx.xx]
(substitute your own domain or IP address)
Enter a PASSWORD to perform call transfers with the Flash Operator Panel:[passw0rd] <a strong password for the FOP>
Use simple Extensions [extensions] admin or separate Devices and Users [deviceanduser]?[extensions] (I just hit ENTER to accept the default of extensions; this means that FreePBX will treat users and devices as single entities called extensions. You can change this later in FreePBX in the Advanced Settings)
Enter directory in which to store AMP executable scripts:[/var/lib/asterisk/bin] (I just hit ENTER to accept the default)
Enter directory in which to store super-user scripts:[/usr/local/sbin] /usr/sbin

If you need to re-run the installer, be sure to delete the config file /etc/amportal.conf first.

I then had to change the user and group owner from root to asterisk for the FreePBX files:

chown -R asterisk:asterisk /home/www/freepbx

I fired up by browser and navigated to, clicked on “FreePBX Administration”, entered the default username and password (admin/admin), and there she was!  Now that it was up and running, I also added the Flash Operator Panel and amPortal to the system startup scripts by editing /etc/rc.local as root and adding the line /usr/sbin/amportal start above exit 0 and started configuring the system. 

Related Posts
I dislike Ubuntu's built in remote desktop service, and use x11vnc instead. Recently I was having a terrible time recently remotely accessing an Ubuntu+Gnome workstation: when I connect from a ...
vsftpd can cause trouble with  slow directory listings or timeouts, but with a little configuration magic you can get this working properly on a CentOS box. All commands will need to ...
Getting Shift Key Working With x11vnc and VNC
Fix vsftpd Slow Directory Listings & Timeouts