How to install AGI in SIP

I am using asterisk 1.4 & mySql server. can any one provide me step by step guidance to install php-agi in my server?

AGI isn’t something that you “install”. Loading Asterisk is about all you have to do.

After that, you only need to load PHP, and create a PHP script that will use it. If you can run the PHP script from the command line, and get it working from there, you should be able to make it work from Asterisk.

Here’s an example of one I built. It goes to a web page, posts a couple of identifying pieces of data, (in this case, their home phone number and their house address number) then gets back the customer data.

The customer data is stored in a file. We were using the information to create a list of customers who were interested in a certain product. If they ended up on this list, we figured they were interested. All we really needed from this was their phone number, account number, house number, and last name. So, that’s what’s written to the file.

[code]#!/usr/bin/php -q

<?php if (!defined('STDIN')) { define('STDIN', fopen('php://stdin', 'r')); } if (!defined('STDOUT')) { define('STDOUT', fopen('php://stdout', 'w')); } if (!defined('STDERR')) { define('STDERR', fopen('php://stderr', 'w')); } while (!feof(STDIN)) { $temp= trim(fgets(STDIN,1024)); if (($temp == "") || ($temp == "\n")) { break; } $s = split(":",$temp); $name = str_replace("agi_","",$s[0]); $agi[$name] = trim($s[1]); } ob_start(); ob_implicit_flush(true); set_time_limit(10); $tv = fopen("/var/log/asterisk/tv/tv.txt", "a"); $custdata = ($1); function ExtractString($str, $start, $end) { $str_low = strtolower($str); $pos_start = strpos($str_low, $start); $pos_end = strpos($str_low, $end, ($pos_start + strlen($start))); if ( ($pos_start !== false) && ($pos_end !== false) ) { $pos1 = $pos_start + strlen($start); $pos2 = $pos_end - $pos1; return substr($str, $pos1, $pos2); } } $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, "http://webpage.com/loginform.html?statereset=yes"); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATON, 0); curl_setopt ($ch, CURLOPT_POSTFIELDS, $custdata); curl_setopt ($ch, CURLOPT_POST, 1); $loginform = curl_exec ($ch); curl_close ($ch); $complete = ExtractString($loginform, "", ""); if ($complete = "Error") { fwrite(STDOUT,"SET CONTEXT tryagain") fwrite(SDDOUT,"EXEC GoTO s|1"); fflush(STDOUT) unset($ch); fclose($tv); fclose(STDIN); fclose(STDOUT); fclose(STDERR); die(); } $stateinfo = ExtractString($loginform, "", ""); $phone = ExtractString($loginform, "", ""); $house = ExtractString($loginform, "", ""); $lastname = ExtractString($loginform, "", ""); unset($ch); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, "http://webpage.com/lastpmt.html?"); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATON, 0); curl_setopt ($ch, CURLOPT_POSTFIELDS, $stateinfo); curl_setopt ($ch, CURLOPT_POST, 1); $lastpmt = curl_exec ($ch); curl_close ($ch); $account = ExtractString($lastpmt, "", ""); fwrite($tv, "P-$phone A-$account H-$house L-$lastname\n"); unset($ch); fclose($tv); fclose(STDIN); fclose(STDOUT); fclose(STDERR); ?>[/code]

To call the script, I used these lines:

exten => s,n,Set(subscriber=CallerPhoneNumber=${callerphone}&CallerAccountNumber=&CallerHouseNumber=${house}) exten => s,n,AGI(lookup.agi|${subscriber}) exten => s,n,Goto(thanksforcalling,s,1)

It’s probably not the best written PHP script in the world, but it worked for me.

Thanks for the help. do i need to configure php or webserver?

You shouldn’t need to configure webserver. PHP, once loaded, should be able to operate your script for you.

Thanks