Configuring Realtime Voicemail on Debian


Realtime has been around for a while now, but operating systems are constantly evolving. Because of this, guides can become outdated. I find myself looking up how to get realtime configured whenever I need to test something, and there’s usually always a complication. This blog post aims to serve as a modern source for getting realtime set up with as few problems as possible. While my examples will be done with Ubuntu as a reference point, this can be applied to a wide range of systems.

This will not be a blog post on how to get Asterisk itself installed and configured. If you haven’t done that, go ahead and get that set up. One thing you do need to do is ensure that ODBC storage is enabled for voicemail. This is an option available in menuselect, under the Applications category. You can select as many options as you’d like for voicemail, but should only have one enabled in modules.conf. Once that’s taken care of, we will need to install some packages.

Initial Setup

We’ll start with ODBC:

sudo apt-get install unixodbc odbcinst

If you don’t have alembic installed already, do that now:

sudo apt-get install alembic

Database Installation

From here, we need to choose our database. I already had MySQL installed, so I went with that. However, another popular (and probably better) choice is MariaDB. I used MariaDB packages in conjunction with MySQL to get everything connected. I’ll stick to MySQL for this blog post, but feel free to use any other supported backend. Let’s install MySQL:

sudo apt-get install mysql-server

It should already be running, but to be sure you can run the following:

sudo systemctl start mysql.service

Database Configuration

Perfect! Now that we have MySQL installed, we need to configure it in a way that allows Asterisk to access it. You should be able to access your MySQL server via root:

sudo mysql

You should see a MySQL command line. From here, we can create our user. Strictly for this example, let’s call it asterisk:

CREATE USER ‘asterisk’@'%' IDENTIFIED BY 'asterisk';

You’ll want something more secure than that, of course! Now that we have our user, let’s create a database and grant permissions to the user:

GRANT ALL PRIVILEGES ON asterisk.* TO 'asterisk'@'%';

Everything should be set up now. You can leave the MySQL console by typing “exit”. Once back to the terminal, you should be able to login with our newly created user:

mysql -u asterisk -p

You can access the database we created by entering the following:

USE asterisk;

There’s nothing in the database yet, so let’s get everything connected and use alembic to do the heavy lifting for us!

Initial ODBC Setup

In order to get a connection, we need another package. The connectors we would normally use for MySQL don’t come by default on modern distributions, so we’ll use MariaDB instead:

sudo apt-get install odbc-mariadb

We need one to locate one thing from this package: If you’re not sure where it was installed, you can use dpkg to locate it:

sudo dpkg -L odbc-mariadb

We should now have everything we need to get things set up! Head over to /etc and open up the odbc.ini file:

cd /etc
sudo vim odbc.ini

This file might be empty (or may not even exist). If that’s the case, create it and fill it with the following contents:

Description = MySQL Server
Driver = MySQL ODBC Driver
Database = asterisk
Server = localhost
User = asterisk
Password = asterisk
Port = 3306
Socket = /var/run/mysqld/mysqld.sock

In the same directory, open odbcinst.ini and add the following:

[MySQL ODBC Driver]
Description = MySQL Connector/ODBC
Driver = /usr/lib/x86_64-linux-gnu/odbc/

Note that the driver location will be the result of whatever you got from the previous dpkg -L command when we installed odbc-mariadb.

Testing ODBC Configuration

To make sure all of this is working, we can enter these commands:

odbcinst -q -d
echo “select 1” | isql -v MySQLServer

If you don’t see [MySQL ODBC Driver] show up for the first command or a “Connected!” response from the second, then things are not configured properly.

Moving on to /etc/asterisk (or wherever your configuration files are located), let’s open up res_odbc.conf and add this:

enabled => yes
dsn => MySQLServer
username => asterisk
password => asterisk
max_connections => 10
pre-connect => yes

At this point, I would start Asterisk and check to see if the connector shows up on the console. An “odbc show” should do the trick.

Voicemail ODBC Configuration

Last but not least, let’s open up voicemail.conf and change the ODBC settings:


We’re almost done! The only thing left to do on the configuration side is setting up the tables in the database. Luckily, alembic makes this incredibly easy. Navigate to your Asterisk source directory and then to the contrib/ast-db-manage. You’ll see several files in here, but the only one we care about is voicemail.ini.sample. Copy it to the same directory without the .sample and open it up. We only need to look at one line. Look for the sqlalchemy.url lines and make sure this is the only one you have:

sqlalchemy.url = mysql://asterisk:asterisk@localhost/asterisk

This line tells alembic the database we are connecting to and with which user. Now we can let alembic populate the database:

alembic -c voicemail.ini upgrade head

You should see several revisions being made. If it didn’t encounter any errors, check MySQL to see if the asterisk database has the voicemail_messages table. If it does, you’re good to go!

Leaving and retrieving a voicemail is the same as usual: VoiceMail and VoiceMailMain. You can go a step further and have your voicemail boxes stored in realtime as well if you want. This can be done with the config.ini alembic file. Another important file to look at when using realtime is extconfig.conf. This tells Asterisk which configuration files it should read from the file system as opposed to the database. There’s a lot of work up front to get realtime working, but it can be a powerful tool.

About the Author

What can we help you find?