Saturday, June 11, 2011

Asterisk 1.8 with MySQL Realtime Support on Ubuntu 10.04 LTS

First of all lets make yourself root otherwise you have to use sudo with each command(s) and have to type password in most cases
sudo su
Update the system and apply updates if there are any
apt-get update
apt-get upgrade

Install all dependencies
sudo apt-get install python-software-properties -y
Import public key
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 175E41DF
Add repository so we can download asterisk 1.8
sudo add-apt-repository "deb http://packages.asterisk.org/deb `lsb_release -cs` main"
sudo add-apt-repository "deb-src http://packages.asterisk.org/deb `lsb_release -cs` main"

Update repository and install any update if needed
apt-get update
apt-get upgrade

Install Asterisk 1.8
sudo apt-get install asterisk-1.8 -y
Install DAHDI
sudo apt-get install asterisk-dahdi -y
That is it, we have sucessfully installed Asterisk 1.8
Next part is to install LAMP package
apt-get install mysql-server mysql-client apache2 php5 libapache2-mod-php5 phpmyadmin php5-mysql -y
Once done, restart all services or restart system
service asterisk restart
service mysql restart
service apache2 restart

Enjoy your new system and have fun with it
I have scripted the whole process, feel free to download it
wget http://ryaz.homeip.net/docs/conf/asterisk.sh
In next part we are going to set asterisk up for MySQL realtime
In this example, I am going to create two accounts and going to set them up so they can make/receive calls from each other. Both accounts will have voice mailboxes as well. I am using internal as my default context, feel free to change any setting
So lets start
Edit sip.conf file
nano /etc/asterisk/sip.conf
Add the following lines in it, the file is pretty long and has broad settings but everything is commented out of the box. Following line will set up basic operation to start and then later on you can go through the file and set the option(s) you need. You can add these lines right after [general] tag
context=internal
rtcachefriends=yes
disallow=all
allow=ulaw
allow=ilbc

Save the file and exit
Now we need to edit extensions.conf file so all use in internal context can make/receive calls
nano /etc/asterisk/extensions.conf
Add the following line right after [general] tag, again the file have broad settings but this will setup the basic context [internal]
[internal]
switch => Realtime/@

You can also add MySQL table name where all extensions are located i.e. switch => Realtime/@extensions
Save the file and exit out of it
Next we need to tell asterisk to look for MySQL database for users information
Edit extconfig.conf file
nano /etc/asterisk/extconfig.conf
Add the following lines in it, I would just add them at the end of the file
sipusers => mysql,asterisk,users ; SIP user
sippeers => mysql,asterisk,users ; SIP peers
extensions => mysql,asterisk,extensions ; SIP extensions
voicemail => mysql,asterisk,voicemails ; SIP voicemailboxes
queues => mysql,asterisk,queues ; SIP queue
queue_members => mysql,asterisk,queue_members ; SIP queue members

Now we need to tell asterisk to connect to MySQL to get all informations
So edit res_config_mysql.conf file
nano /etc/asterisk/res_config_mysql.conf
Our database for this example is asterisk so add the following in that file [append]
[asterisk]
dbhost = localhost
dbname = asterisk
dbuser = mysqluser
dbpass = mysqlpass
dbport = 3306
dbsock = /var/run/mysqld/mysqld.sock
requirements=warn ; or createclose or createchar

Adjust dbuser and dbpass to your settings, this is mysql user privilage account. You can always use root for testing if you are not sure about the account
Okay at this point our asterisk box is ready and all configured !
Lastly we need to create database in mysql
So connect to mysql and create database, first import the asterisk.sql script to create database and its related tables
wget http://ryaz.homeip.net/docs/conf/asterisk.sql
Now connect to mysql and create the database and its table using asterisk.sql script, replace mypassword with your root's password
mysql -u root -pmypassword
source asterisk.sql;

All done!

Configure hard/soft sip phones and have fun
As always feel free to email me if you have any question(s)

Did my efforts worked for you ? want to say thank you ?
You can buy me a beer, I would appreciate that !




16 comments:

  1. Typo "apt-get install .... libapache2-mod-php5" not "libapache2-mode-php5"

    Thx

    ReplyDelete
  2. wget http://cns.selfip.net/articles/conf/asterisk.sql
    gives error 404

    ReplyDelete
  3. Can not download files ... please fix it!

    ReplyDelete
  4. Hey.. can not download files. Broken link.

    ReplyDelete
  5. Sorry folks try the following
    http://www.ryazkhan.net/docs/conf/asterisk.sql

    ReplyDelete
    Replies
    1. http://ryaz.homeip.net/docs/conf/asterisk.sql

      Delete
  6. Timeless European-inspired architecture marry
    contempo design and amenities offers its resident a truly alluring abode to call home.

    the interlace condo

    ReplyDelete
  7. Hi

    I followed the post and everything worked for me, however i want to check as to whether my asterisk is really connected to mysql and issued the command realtime mysql status and to my surprise the command is not recognized. how can i be sure that it is connected. asterisk 1.8.10 in ubuntu 12.04

    ReplyDelete
    Replies
    1. realtime mysql status should show you the status, it the command is not recognized then you probably don't have it installed at all, so installing it will fix the issue, for 12.04 thats all you need http://www.ryazkhan.net/?node=2&sub=16

      Delete
  8. Dear Ryaz,

    I cant setup realtime data from mysql.. according your config.. my asterisk showing no ODBC connected.

    ReplyDelete
  9. Hello Ryaz i have completed all the configuration setting in realtime asterisk now mysql driver loaded properly now problem is when i connect sip phone to given asterisk server then it will show the error message == Connect attempt from '192.168.10.101' unable to authenticate

    ReplyDelete
  10. Hello ... thank's for the post .... but I can't find the file asterisk.sql ... can you help-me ?

    ReplyDelete