This is just a small gathering of commands and best practices for installing Asterisk and FreePBX on Ubuntu. This worked for me, it has some shortcomings but should work on most of the cases. Feel free to add some comments on better ways of installing it.
The following packages will be installed:
- Asterisk 126.96.36.199
- FreePBX 2.8.1
I started with a fresh install of Ubuntu Server 10.10, but if you already have it installed, results should be similar. While installing I selected the LAMP and SSH services, those are pretty basic services which you will need. If you have finished a fresh install, or haven’t updated your system in a while, I suggest running the following lines before continuing with this guide.
sudo apt-get update sudo apt-get upgrade
Although not necessary for running Asterisk and FreePBX, I suggest that you install a MTA agent. If you think this is unnecessary on your setup skip to the next section. Postfix is my MTA of choice, so we are going to install it. When prompt about which configuration should be done to it, select Internet with smarthost, just confirm the other options.
sudo apt-get install postfix
Okey, postfix installed, time to edit the basic configuration, add or change the following lines to
relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_use_tls = yes
The password for accessing your external relay must be saved to
/etc/postfix/sasl_passwd, add the following this file:
Fix the permissions on this file:
sudo chmod 400 /etc/postfix/sasl_passwd sudo postmap /etc/postfix/sasl_passwd
Add the appropriate ca-certificate to
/etc/postfix/cacert.pem. For gmail, that’s Thawte Consulting, so add their ca-certificate.
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
sudo /etc/init.d/postfix restart
Avoid sending mail as root
Edit /etc/aliases, add the following:
Run the new alias command:
Create a /etc/postfix/sender_canonical file mapping user -> email such as:
Run the following lines:
sudo postmap hash:/etc/postfix/sender_canonical
Add the following line to /etc/postfix/main.cf:
sudo /etc/init.d/postfix restart
When you selected the LAMP service on your Ubuntu install, you automatically got PHP5 installed. Now you just have to install some additional packages that didn’t get installed. So run the following line to install them.
sudo apt-get install php5-gd php-pear php-db sox curl
One might find useful to have phpMyAdmin installed for managing the MySQL database used by FrePBX and Asterisk. If you don’t know what phpMyAdmin is, you can skip to the next section.
Ubuntu 10.10 provides pre-compiled asterisk packages, using that is way more easier than backing your own asterisk. Run the following to install it, and all of its dependencies.
sudo apt-get install asterisk asterisk-mysql asterisk-mp3 asterisk-sounds-extra
This is a really short how-to for configuring Dahdi, it just covers the bare minimum, but it works ok. First of all, load the necessary kernel modules, in my case for a TDM400P it was the following line:
sudo modprobe wctdm
You might wanna check if the module was loaded and configured your hardware properly, so run a
dmesg. If everything is alright, you have to create the dadhi configuration file. That’s really easy, just run:
sudo dahdi_genconf -vvvv
Warning: Be careful when you run this on a production system, it will override the current dahdi configuration file.
/etc/dahdi/system.conf and set the correct loadzone and defaultzone for your country code. I like to use vim to edit configuration files, but you can use any text editor.
sudo vim /etc/dahdi/system.conf
Now check if channels are up an running, run dahdi_cfg:
sudo dahdi_cfg -vvv
Next you have to edit
/etc/asterisk/chan_dahdi.conf to configure the channels, this is what asterisk will see and use to send and receive calls.
Before running the install command, you have to configure your apache server. I prefer to use virtual host, and as of lately I have adopted the following layout for my server:
conf I store the necessary vhost configuration, in
public lives the public accessible files, and
log hosts the logging files. Feel free to use your own personal taste on installing webapps. For those who want to stick with the how-to, create the needed directories:
sudo mkdir /var/www/pabx.domain/ sudo mkdir /var/www/pabx.domain/conf sudo mkdir /var/www/pabx.domain/log sudo mkdir /var/www/pabx.domain/public
Now create a /var/www/pabx.domain/conf/vhost.conf file:
sudo vim /var/www/pabx.domain/conf/vhost.conf
And paste the following lines, change it accordingly to your domain.
<VirtualHost *:80> ServerName pabx.domain ServerAlias pabx.domain ServerAdmin email@example.com ErrorLog /var/www/pabx.domain/log/error.log CustomLog /var/www/pabx.domain/log/access.log combined DocumentRoot /var/www/pabx.domain/public <Directory /var/www/pabx.domain/public> Options Indexes FollowSymLinks MultiViews Order allow,deny AllowOverride All Allow from all </Directory> <Directory /var/www/pabx.domain/public/admin> AuthType Basic AuthName "Restricted Area" AuthUserFile freepbx-passwd Require user admin </Directory> </VirtualHost>
With the file created, add the vhost to the sites-enabled directory, with:
sudo ln -s /var/www/pabx.domain/conf/vhost.conf /etc/apache2/sites-available/pabx.domain cd /etc/apache2/sites-enabled/ sudo ln -s ../sites-available/pabx.domain
For now, create an htpasswd file to protect the access to freepbx.
sudo htpasswd -c /etc/apache2/freepbx-passwd admin
And finally, restart apache.
sudo /etc/init.d/apache2 restart
Your Asterisk install should be working by now, so it’s time to install a nice web user interface. Ubuntu doesn’t provide a package for FreePBX, so grab the latest stable source code from FreePBX site.
cd /tmp wget http://mirror.freepbx.org/freepbx-2.8.1.tar.gz cd /usr/src sudo tar xvzf /tmp/freepbx-2.8.1.tar.gz cd freepbx-2.8.1/
You can equally extract the tarball on your home directory. It doesn’t make any difference. Now it’s time to create the database, the user used to access it, and populate the basic tables. This will create and import the basic tables to asterisk and asterisk cdr database, run this from the recently extracted directory.
mysqladmin create asterisk -u root -p mysqladmin create asteriskcdrdb -u root -p mysql -u root -p asterisk < SQL/newinstall.sql mysql -u root -p asteriskcdrdb < SQL/cdr_mysql_table.sql
With the tables in-place, it's time to create the user with privileges to access and edit those tables. Open a mysql prompt with:
mysql -u root -p
On the prompt run the following queries:
GRANT ALL PRIVILEGES ON asterisk.* TO asterisk@localhost IDENTIFIED BY 'badasspassword'; GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asterisk@localhost IDENTIFIED BY 'badasspassword'; flush privileges; quit;
Don't forget to change the password!
Before running the install command, make a copy of /etc/asterisk/modules.conf. FreePBX rewrites the file and trashes Asterisk installation. If you restart Asterisk after installing FreePBX Asterisk dies with no message.
sudo cp /etc/asterisk/modules.conf ~/asterisk-modules.conf
Ok, we are ready to install freepbx to /var/www/pabx.domain/public:
The install script will ask for some configuration data, eg. were to install freepbx (/var/www/pabx.domain/public), sql password, asterisk password, etc. Take note of the passwords you used, you might need them later.
The output from the install script is somewhat like this:
... Enter your USERNAME to connect to the 'asterisk' database: [asteriskuser] asterisk Enter your PASSWORD to connect to the 'asterisk' database: [amp109] badasspassword Enter the hostname of the 'asterisk' database: [localhost] Enter a USERNAME to connect to the Asterisk Manager interface: [admin] Enter a PASSWORD to connect to the Asterisk Manager interface: [amp111] Enter the path to use for your AMP web root: [/var/www/html] /var/www/pabx.domain/public Enter the IP ADDRESS or hostname used to access the AMP web-admin: [xx.xx.xx.xx] pabx.domain Enter a PASSWORD to perform call transfers with the Flash Operator Panel: [passw0rd] password Use simple Extensions [extensions] admin or separate Devices and Users [deviceanduser]? [extensions] Enter directory in which to store AMP executable scripts: [/var/lib/asterisk/bin] ...
Restore asterisk-modules.conf file, which you backed up before installing FreePBX:
sudo cp ~/asterisk-modules.conf /etc/asterisk/modules.conf
Apache runs as www-data, Asterisk as user asterisk, so we have to change some permission to make both programs work together. First, add www-data to asterisk group:
sudo adduser www-data asterisk
Fix the permissions from amportal, add these lines to the end of
AMPASTERISKUSER=www-data AMPASTERISKGROUP=asterisk AMPASTERISKWEBUSER=www-data AMPASTERISKWEBGROUP=asterisk
Everything in place, time to start amportal:
sudo amportal start
Open your web browser and go to http://pabx.domain/ and you will be greeted with FreePBX site. I strongly suggest you to upgrade and install the FreePBX modules you will need, so go to Modules Admin and click on Check for online updates.
Start asterisk with amportal
Before we finish, lets make amportal script to manage asterisk and run it through the safe_asterisk script, for that, we have to remove asterisk from rc.d:
sudo update-rc.d -f asterisk remove
Now edit safe_asterisk, to make sure it runs on background, edit the variable BACKGROUND to zero:
sudo sed -e s/BACKGROUND=0/BACKGROUND=1/ -i /usr/sbin/safe_asterisk
We have to start amportal after booting, so call amportal start in
/etc/rc.local. Edit your /etc/rc.local and add the following line before the exit 0 line.
Reboot your machine, and check that everything is still working. Have fun!