Set up Asterisk Server on Ubuntu VM in VirtualBox to test Linphone : Part 1

When working with VOIP, it’s helpful to have Asterisk server on the development machine. Asterisk server is Digium’s software implementation of PBX (private branching exchange), which provides features like voice calls, video and voice conferencing, and messaging.  This blog entry details how to set up and apply basic configuration to an Asterisk on an Ubuntu virtual machine.

Step 1: Install VirtualBox on your machine.

VirtualBox is a free virtualization product from Oracle. After installing VirtualBox, start the app and click “New” to create a new virtual machine. Enter name for your new virtual machine. I used “ubuntu” here. The Type and Version are then automatically selected. Adjust to what matches your setting.

You can adjust the memory size. I just used the defualt memory size: 512 MB Select “Dynamically allocated”. It’s easier to configure but not as fast as the “fixed size” hard drive.

Adjust the virtual machine name if desired, as well as the hard disk size. Be mindful of the disk space available on the host machine. Then click “Create” to start creating the virtual machine.

Then power up the new machine by clicking the power button.

Upon power up, you will be prompted to enter a disk or a iso file. Browse to the Ubunto ISO file (can be obtained from Ubuntu download site). The user created during installation has the root privilege, so be sure to write down the password.

After installing, you can turn on the virtual machine. This is what my Ubuntu 14 virtual machine looks like in VirtualBox

Step 2: Build Asterisk and its depended libraries

To install prerequisite: Install the following packages

  • libxml2-dev
  • libncurses-dev
  • build
  • build-essential
  • linux-headers-`uname -r`
  • openssh-server
  • libssl-dev
  • libxml2-dev
  • libnewt-dev
  • sqlite3
  • libsqlite3-dev
  • pkg-config
  • automake
  • libtool
  • autoconf
  • git
  • subversion
  • uuid
  • uuid-dev

At the commandline, use apt-get to install:

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y build-essential linux-headers-`uname -r` openssh-server libssl-dev libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git subversion uuid uuid-dev

Then download the source tar ball for dahdi, libpri, and asterisk

wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete-current/dahdi-linux-complete-current.tar.gz
wget http://dowloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz

To build and install dahdi

tar xvfz dahdi-linux-complete-current.tar.gz
cd dahdi-linux-complete-
make all
sudo make install
make config

To build and install libpri

tar xvfz libpri-1.4-current.tar.gz 
cd libpri-1.4.15
make 
sudo make install

To build Asterisk

./configure
contrib/scripts/get_mp3_source.sh
make menuselect (select modules you wished to include)
make 
sudo make install
sudo make config
sudo make samples (to make sample configurations)

Note, if you would like to enable IAX, make sure the channel driver for  IAX is selected during “make menuselect” step:

Step 3: Create Asterisk User and Run Asterisk with default setting

Then create asterisk user

sudo adduser asterisk --disabled-password --no-create-home --gecos "Asterisk User"
sudo chown asterisk. /var/run/asterisk
sudo chown -R asterisk. /etc/asterisk
sudo chown -R asterisk. /var/{/lib,log,spool}/asterisk
sudo chown -R asterisk. /usr/lib/asterisk

Start asterisk server

sudo service asterisk start

Then test connecting to asterisk

sudo asterisk -rvvvvvv

If it connects successfully, you should see the asterisk commandline prompt

In Set up Asterisk Server on Ubuntu VM in VirtualBox to test Linphone : Part 2 , I will show you how to configure asterisk to accept connection from linphone.

24 Comments

  1. Mohit Rawat

    Hi, While running the below command I am getting the following error.Kindly help. Thanks in advance.
    asterisk-13.4.0$ sudo asterisk -rvvvvvv
    Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?

  2. Mohit Rawat

    Hi, While running the below command I am getting the following error.
    asterisk-13.4.0$ sudo asterisk -rvvvvvv
    “Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?”

    • Jessica Chiang

      Your asterisk service may not be running. Command to restart asterisk service: “sudo service asterisk restart”

      • TimePasser

        If you are going to restart the service in CLI try “core restart now”

  3. mohit

    After I have installed asterisk I have tried to connect with it using asterisk -rvvvvc. But it gave me an following error message. Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?)

    How can I solve this issue.Please help me.

    • Jessica Chiang

      Did you start the asterisk service? By the way, you may need to be root to do it.
      Command to restart asterisk service: “sudo service asterisk restart”

  4. Thank you!
    I’m having issues installing dahdi in a virtual machine (cloud)
    when I run make clean it said:
    “You do not appear to have the sources for the 2.6.32-39-pve kernel installed.”
    I was using:

    mkdir /usr/src/asterisk
    cd /usr/src/asterisk
    wget http://downloads.vicidial.com/required-apps/asterisk-1.8.23.0-vici.tar.gz
    wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
    tar -zxf dahdi-linux-complete-current.tar.gz
    cd dahdi-linux-complete-2.9.1.1+2.9.1
    make clean

    • Jessica Chiang

      You are using a different build of asterisk from that in the tutorial, so there might be additional required libraries. Are you trying this on Debian? Also, I would suggest just installing 2.6.32-39-pve kernel source.

  5. h

    when I write the second commanline to install packages, it says ‘Unable to locate package linux-headeruname -r’. Please help. I am not a Linux guy.

  6. My partner and I stumbled over here by a different page and thought I might as
    well check things out. I like what I see so now i’m following you.
    Look forward to checking out your web page
    again.

  7. Greaat bloig you have here but I was wanting to know if you knew of any message boards
    that covger the same topics talked about here?

    I’d really love to be a part of group where I can get feed-back
    from other experienced individuals that share the same interest.
    If you have aany suggestions, please let me know.
    Thank you!

  8. Thank you for the auspicious writeup. It actually was a
    entertainment account it. Glance complicated to more introduced agreeable from you!
    By the way, hhow can we communicate?

  9. Hello there I am so grateful I found your blog, I really found you
    by error, while I was searching on Aol for something else,
    Anyhow I am here now and would just like to say thank
    you for a fantastic post and a all round entertaining blog (I
    also love the theme/design), I don’t have
    time to browse it all at the moment but I have saved it and also added
    your RSS feeds, so when I have time I will be back to read much more, Please do keep up
    the fantastic work.

  10. Hey there! This post could not be written any better!
    Reading this post reminds me of my old room mate!
    He always kept talking about this. I will forward
    this write-up to him. Fairly certain he will have a good read.
    Thank you for sharing!

  11. Nadeem

    After installation of ubunto i could not find the black screen where i write the commands of aterisk

Leave a Reply to internet marketing Cancel reply