Linksys SPA3102 And FreePBX On Ubuntu 10.04


I wanted to setup a Private Branch eXchange(PBX) system using Asterisk server at home. As I already had a traditional land line (PSTN or POTS line) I needed something to bridge the computer to the land line. My idea of having a PBX at was to route as many calls over VOIP which tends to be cheaper like Skype and still use a traditional landline for emergencies as well as just having a landline number.


Originally I started writing a post on how to get a PBX with a web interface going on Ubuntu 8.04. However once I had it all installed it wasn’t working 100%. I had issues with permissions and FreePBX had problems with the operation panel. Fast forward 2-3 years and I’m back doing it again but this time on the next LTS release and 7 minor release later from FreePBX.

Ubuntu 10.04 LTS


Asterisk is a free and open source software for PBX. It’s what you see in companies to manage and route all their phones calls. Asterisk is a PBX engine which has several front end engines and even a distribution specially for PBX box called Trixbox. If you just want a headless PBX then installing Asterix will suffice however I was not technically skilled enough to create all configuration files from scratch and also a nice front end will go a long way for the Wife Acceptance Factor (WAF). This is where FreePBX comes in.


FreePBX is GUI interface wrapper for Asterisk. Ubuntu has a FreePBX package in it’s repository. FreePBX uses a web front end so it can be accessed anywhere and makes administration a lot easier. It uses modules to extend the functionally like add-ons in Firefox. These include group pickup to Parking Lots.

With FreePBX this sorts out the software side of my PBX.

Linksys SPA3102

This an Analogue Telephone Adaptor(ATA) which is used to convert a land line to a digital network and a traditional land line phone to the network too. The hardware has been around for a long time and it does work with Asterisk. The SPA(Sipura)3102 can be used as a standalone PBX box too but in my case it will be used to forward incoming and outgoing calls.

The SPA3102 also has a web interface but it can also be used to act as a router at the same time. The web interface is very basic and not very user friendly but has a lot of options making it very customizable and configurable.

Asterisk And FreePBX Install

Switch to root user before installing sudo su.

Install MySQL sudo apt-get install mysql-server
When prompted for password enter one.

Install MySQL modules, PHP, kernel headers for compiling code, apt-get install build-essential linux-headers-`uname -r` openssh-server bison flex apache2 php5 php5-curl php5-cli php5-mysql php-pear php-db php5-gd curl sox libncurses5-dev libssl-dev libmysqlclient15-dev mpg123 libxml2-dev

Go to /usr/src cd /usr/src/
and download the Asterisk source files

xargs wget << SOURCES SOURCES

Un-tar(zip) all the source files in /usr/src/ tar xvf dahdi-linux-complete-2.2.1+2.2.1.tar.gz
tar xvf libpri-
tar xvf asterisk-
tar xvf asterisk-addons-

Compile Asterisk in the following order:
cd dahdi-linux-complete-2.2.1+2.2.1
make all && make install && make config
cd ../libpri-
make && make install
cd ../asterisk-
make && make install
make samples
cd ../asterisk-addons-
make && make install
make samples
Download and extract extra sounds cd /var/lib/astersik/sounds
wget -O - | tar xvfz -

Create an Asterisk user account on the Linux box adduser asterisk --disabled-password --no-create-home --gecos "asterisk PBX user"
adduser www-data asterisk

Make a backup of the Asterisk configuration file cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig

Change the Asterisk config to run as a correct user sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf

Create the Asterisk service script which will start and stop the Asterisk demon:

cat > /etc/init.d/asterisk <<-END_STARTUP #!/bin/bash ### BEGIN INIT INFO # Provides: asterisk # Required-Start: \$network \$syslog # Required-Stop: \$network \$syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Asterisk daemon. # Description: This script handles start/stop states of asterisk. ### END INIT INFO set -e set -a PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="Asterisk" NAME=amportal DAEMON=/usr/sbin/\$NAME test -x \$DAEMON || exit 0 d_start() { amportal start } d_stop() { amportal stop } d_reload() { amportal restart } case "\$1" in start) echo -n "Starting \$DESC: \$NAME" d_start echo "." ;; stop) echo -n "Stopping \$DESC: \$NAME" d_stop echo "." ;; restart|force-reload) echo -n "Restarting \$DESC: \$NAME" d_stop sleep 10 d_start echo "." ;; *) echo "Usage: \$SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3


exit 0

Ensure the permissions of the demon script is correct chmod 755 /etc/init.d/asterisk

Make Asterisk start up when the computer starts update-rc.d asterisk defaults 90 10

Download and extract FreePBX
cd /usr/src/
wget -O - | tar xvfz -
cd freepbx-2.7.0/

Copy the Amportal configuration cp amportal.conf /etc/

Set environment variables for the current session. These variables will store the password for MySQL access so that the script can be 100% automated. One is the admin password and the other is the Asterisk database user password. These variables should clear once the terminal session ends but it is advised to remove them from the bash history in ~/.bash_history
export MYSQL_ROOT_PW=abcd
export ASTERISK_DB_PW=wxyz

Run the database scripts:
mysqladmin -u root -p${MYSQL_ROOT_PW} create asterisk
mysqladmin -u root -p${MYSQL_ROOT_PW} create asteriskcdrdb
mysql -u root -p${MYSQL_ROOT_PW} asterisk < SQL/newinstall.sql
mysql -u root -p${MYSQL_ROOT_PW} asteriskcdrdb < SQL/cdr_mysql_table.sql

mysql -u root -p${MYSQL_ROOT_PW} <<-END_PRIVS GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY "${ASTERISK_DB_PW}"; GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY "${ASTERISK_DB_PW}"; flush privileges; END_PRIVS

Edit the amportal configuration file with the database username and password
sed -i "s/# \(AMPDBUSER=.*\)/\1/" /etc/amportal.conf
sed -i "s/# \(AMPDBPASS=\).*/\1${ASTERISK_DB_PW}/" /etc/amportal.conf
sed -i "s@\(AMPWEBROOT=\).*@\1/var/www/@" /etc/amportal.conf
sed -i "s@\(FOPWEBROOT=\).*@\1/var/www/panel@" /etc/amportal.conf
sed -i "s@\(FOPWEBADDRESS=\).*@PUTIPADDRESS@" /etc/amportal.conf

Change the max PHP file upload size to 120mb in Apache
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php5/apache2/php.ini

Change the files and directories so that Asterisk has access to them
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /var/www/

Remove line ending from the Asterisk configuration file.
sed -i '1 s/\(\[directories\]\).*/\1/' /etc/asterisk/asterisk.conf

Start Asterisk
./start_asterisk start

Install FreePBX

Restart Apache server
/etc/init.d/apache2 restart

Create a symlink to the "Music On Hold"(MOH) files
ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3

Start FreePBX
amportal start

Asterisk / PBX Terminology

Before I go into configuring the PBX itself it is worth knowing the terminology behind the technology.

Configure FreePBX

First thing to do is set up extensions. Extensions are independent to any available routes as by default Asterisk treats any number dialled as an internal number. Below are steps to create 2 extensions. One number will eventually be assigned to the phone attached to the Linksys SPA3102 and the other for another hard/softphone.

  1. Go to Setup > Basic > Extensions menu item.
  2. Ensure "Generic SIP Device" is selected in the Devices drop down box.
  3. Enter the following details:
    1. User Extension - Phone number of extension E.G 1000
    2. Display Name - Friendly name
    3. Voicemail & Directory Status - Enable this if you want the user to have voicemail facilities
    4. Secret - Leave blank for now but this is the password for the extension.
  4. Submit the changes.
  5. Click on the new extension listed on the right hand side of the Extensions page. This will edit the extension
  6. Under Device Options section change the Mailbox by removing the @device suffix and just leave the extension number in the field.
  7. Submit the changes again.
  8. Repeat the steps above again to create a second extension, changing the extension number, display name and the mailbox setting E.G 1001
  9. Apply the changes to make it take effect.

At this point I would download a SIP softphone such as X-Lite on two computers and test out the 2 extensions created. Using the X-Lite or other softphones is beyond this article.

For Dialling out of the Sipura 3102 a Trunk is needed as well as configuring the outbound route.

  1. Go to Setup > Basic > Trunks in FreePBX
  2. Click on the Add SIP Trunk
  3. Fill in the following fields:
    1. Trunk Description - A friendly name for the trunk. This can be anything
    2. Outbound Caller ID - Full telephone number of the landline including area code.
    3. CID Options - Any
    4. Maximum Channels - 1
    5. Dial Rules - Leave blank
    6. Outbound Dial Prefix - Leave blank
    7. Trunk Name - A memorable name which will be used in the Sipura configuration
    8. Peer Details:


      Change [host] to the IP address of computer hosting Asterisk / FreePBX and [username] to username to be used by Sipura

    9. Leave the remaining fields blank.
  4. Submit Changes.
  5. Go to Setup > Basic > Outbound Routes
  6. Click on 0 9_outside (or create a new one)
  7. Change the settings to as follows:
    1. All fields should be blank or left as default up to Dial Patterns.
    2. Dial Patterns - 9|.
    3. Trunk Sequence - Select the Trunk created above.
  8. Submit changes.
  9. Apply the changes.

The above setting outbound route requires a 9 to be dialled followed by the number to be dialled. The dial pattern can be changed later.

Create a new inbound route for the landline to Asterisk via SPA3102:

  1. Go to Setup > Inbound Call Control > Inbound Routes
  2. Change the following settings:
    1. Description - A meaningful name for the inbound route
    2. DID Number - Enter the landline telephone number including the area code.
    3. Set Destination - Set where the landline call should go to. This can be voicemail or an extension
  3. Submit changes.
  4. Apply Settings

It is worth mentioning here that there is a module in FreePBX called Ring Group which would allow a group of extensions to be named as a destination. This means anyone in the group will have their phone ring when someone rings the landline.

As a recommended step check if a password has been set on the admin web page. Clear out the browser's cookies and cache. Go to the Freepbx page and click on the FreePBX Administration link it should prompt for a password. If not edit the default admin account or add a new account under Setup > Basic > Administration

Notice there is a warning under "General Settings". This means the authentication has not been turned on. Submit the changes and apply them once completed. Go to the Freepbx box and edit the file /etc/amportal.conf Look for the line AUTHTYPE=none and change it from none to database.

Setting Up SPA3102

Out of the box the ATA is configured to act as a router and has the web interface disabled on the WAN port. I will be putting SPA3102 into an existing network so I need to enable the WAN port and turn off the DHCP. The WAN port needs to be enabled so that it can connect to the local network instead of the box expecting a modem and turning off DHCP will stop two devices assigning an IP to the computers on the network.

Plug a telephone into phone socket of the SPA3102 and the power in the power socket. Pick up the phone and dial ***** (5 asterisks) and then 7932 and then 1. Hang up or press #.

Now plug the network cable into the Internet port of the SPA3102 NOT THE ETHERNET PORT. Point your browser to the IP address of the SPA3102. To find out what the IP is you should be able to check on your router or dial ***** (5 asterisks) > 110 on your phone.

Just like a router, a webpage with settings and status of the device should appear. Use the screenshots below and set all the settings below:

The settings are for UK and I have change the tones in the Voice > Regional settings. Others such as the daylight savings are aligned to the UK time zone.

The following needs to be configured according to the environment.
Voice > Line 1 > Proxy and Registration

Voice > Line 1 > Subscriber Information

Voice > PSTN Line > Proxy and Registration

Voice > PSTN Line > Dial Plans

Installing Asterisk and FreePBX on a vmware instance of Ubuntu 10.04 (Lucid) alpha3

UK Regional Settings for Cisco, Linksys & Sipura Devices.

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Hardware, Linux, PBX and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

18 Responses to Linksys SPA3102 And FreePBX On Ubuntu 10.04

  1. quixote says:

    I was following along on your nice list of steps. (Copy from this page, ctrl-shift-v to terminal.) I started at the “Make a backup of the Asterisk configuration file” step because Asterisk was installed using synaptic, and asterisk user was already added. No error messages. But when I get here:

    I get this error message:
    # ./install_amp
    -su: ./install_amp: /usr/bin/php: bad interpreter: No such file or directory

    There is indeed no /usr/bin/php. But php5 is installed. (I think!) It works as part of my LAMP server. Phpmyadmin runs. Etc. etc. What am I missing? I’m running Lucid. It’s frustrating to be so close and trip up here! install_amp is in /usr/src/freepbx-2.8.0. It’s executable, and that dir is on the PATH.

  2. quixote says:

    I found part of the problem: php5-cli needs to be installed. Did that. Now it’s telling me:

    Checking for PEAR DB..FAILED
    [FATAL] PEAR must be installed (requires DB.php). Include path: .:/usr/share/php:/usr/share/pear

    /usr/share/php exists. /usr/share/pear does not. I’ll keep trying to find what else needs installing, and coming back with questions. :S

  3. quixote says:

    Okay- it occurred to me my problem might be coming into the middle of the recipe…. Installed all the other packages under this step “Install MySQL modules, PHP, kernel headers for compiling code” and this time it seems to have installed. When all else fails, read the instructions….

    I’ll come back and let you know whether it’s running for me in a bit. Have to go deal with Real Life for a while :(.

  4. Chasky says:

    I just finishes the installation on my test laptop… everything when good apart from mysql installation.

    I’d already a mysql instance on my machine so it didn’t asked me for password… I’d done apt-remove autoremove to mysql instance, hoping to get everything deleted… it wasn’t the case… luckily for me I could remember the password so I kept on going from there.

    I just had left the configuration part… but it will be tricky to disconnect the SPA3102 since I’m using it a lot.

    this is a great how-to… very easy and straight forward… big thanks!!!!

  5. lee says:

    Very nice tutorial!!!

    I followed it to install asterisk on my ubuntu server 9.10.
    I have not configured the Linksys 3102 yet since it’s in “production”, and asterisk is just for me to play with.


  6. Ubunter says:

    Thanks for the tutorial, I follow it, and I just have small detail, I think it’s better and easer then setup the Asterisk service script, just by issuing the command make config after the make samples &make progdocs, it’s will create automatic config files to be loaded in init.d, you don’t think so?

    Will, it’s not only that, meanwhile I’m the must newbie in asterisk and it’s my first installation, just after starting I create a trunk-sip with inbound rout, and drive it to an extension which I created.
    Just when I do cli>sip reload& sip peers I get:
    1092/1092 1**.72.2**.** D N A 35658 OK (203 ms)
    MessageNet/5344*** 21*.*7.*9.76 5061 Unmonitored

    And sure, when I want to call to my DID, i get error…
    I had been created to extension, both are working, calling in receiving calls internally, also, I could call from outside directly to the sip:1092@myip
    But no inbound, neither outbound routs, thanks for advice…


  7. Danny says:


    Just to clarify:

    1. You have a SIP trunk with inbound route set
    2. Have to extensions which can make and receive calls from internal and external
    3. Calling the DID for the SIP trunk does not work?


    – Danny

  8. Ubunter says:

    Hi Danny,
    Thanks for answer…
    Indeed, I solved the inbound issue, by registering directly in the sip.conf file, with register>…etc.
    Right now, all incoming routs are working properly…

    But I’m turning since 2 days, no way to get outbound routs. Seting up an outbound plan in the PBX Gui, and reload sip from CLI, I get outbound error in the client, and in the log I have:

    [Nov 2 17:45:35] WARNING[6216] file.c: File check-number-dial-again does not exist in any format
    [Nov 2 17:45:35] WARNING[6216] file.c: Unable to open check-number-dial-again (format 0x4 (ulaw)): No such file or directory
    [Nov 2 17:45:35] WARNING[6216] app_playback.c: ast_streamfile failed on SIP/1092-00000053 for silence/1&cannot-complete-as-dialed&check-number-dial-again,noanswer

    So much newbie I’m to understand this log meaning, no idea where’s my mistake…


  9. hi your tutorialis very interesting , i have one spa 3102 used how incoming trunk for one ivr but my problem is that this not answer the call, only ring and in my cli show that the call is incoming

  10. Hi thanks for your quickly answer, i dont explain very good,
    I have a server whit the latest elastix, and other whit freepbx 2.8, i use my spa 3102 how a inbound trunk how a ivr, when i call the cli show the answer of my ivr, but the spa only ringing and not can ear my ivr, think that the problem is in the spa.

    my sip_additional.conf is


  11. Max says:

    Just wanna say thanks! Worked out nicely, using the current versions. Only had to change the starup script from DAEMON=/usr/sbin/\$NAME to DAEMON=/usr/local/sbin/\$NAME, and moved it to https with an additional .htaccess.

    • Danny says:

      Hi Gregory,

      I’m not sure if I can help you but I need more details like the compile error message?

      – Danny

  12. Danny says:

    Another useful configuration to try:

    Basic Configuration

    The following values on the Regional tab will need to be changed to support UK tones and alerts.

    Dial tone: 350@-19,440@-22;10(*/0/1+2)
    Ring back: 400@-20,450@-20;*(.4/.2/1+2,.4/2/1+2)
    Busy tone: 400@-20;10(.375/.375/1)
    Reorder tone: 400@-20;10(*/0/1)
    SIT 1 tone: 950@-16,1400@-16,1800@-16;20(.330/0/1,.330/0/2,.330/0/3,0/1/0)
    MWI dial tone: 350@-19,440@-22;10(.75/.75/1+2)
    CWT1 cadence: 30(.1/2)
    CWT2 cadence: 30(.25/.25,.25/.25,.25/5)
    CWT frequency: 400@-10
    Ring 1 cadence: 60(.4/.2,.4/2)
    Ring 2 cadence (used for BT Call Sign): 60(1/2)
    Ring 3 cadence (used for BT Ring Back): 60(.25/.25,.25/.25,.25/1.75)
    Ring 4 cadence: 60(.4/.8)
    Ring 5 cadence: 60(2/4)
    Time Zone: GMT
    FXS Port Impedance: 370+620||310nF
    Caller ID Method: ETSI FSK With PR(UK)
    Daylight Saving Rule: start=3/-1/7/2:0:0;end=10/-1/7/2:0:0;save=1:0:0

    PSTN line settings for SPA-3000:

    PSTN Disconnect Detection
    Detect CPC: yes
    Detect Polarity Reversal: no
    Detect PSTN Long Silence: yes
    PSTN Long Silence Duration: 30
    Min CPC Duration: 0.09
    Detect Disconnect Tone: yes
    Disconnect Tone: 400@-30;20(*/0/1)

    International Control

    FXO Port Impedance: 370+620||310nF
    On-Hook Speed: 3ms (ETSI) (seems right – UK is ETSI)
    Current Limiting Enable: yes (seems right – UK should be approving to CTR21)
    Ring Validation Time: 256ms
    Ring Indication Delay: 0
    Ring Timeout: 12

Leave a Reply