Asterisk can be used to originate calls from a web page. Asterisk Manager Interface (AMI) allows you to manage call origination. AMI also allows external programs to control Asterisk.

For doing this, you should have

  • A working Asterisk server
  • A SIP termination provider for sending calls out
  • A webpage for entering phone numbers

You have to first create a manager user in Asterisk.  This is created inside /etc/asterisk/manager.conf file

Move the existing manager file using the command

mv /etc/asterisk/manager.conf /etc/asterisk/manager-bk.conf

Create a new manager file

touch /etc/asterisk/manager.conf

Add the below contents to the newly created manager.conf file

enabled = yes
port = 5038
bindaddr =
secret = password
read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,config,command,reporting,originate,message

Now, create a php script,  and the following contents to it. Your webpage will be posting numbers to this php script. It will then connect to Asterisk using AMI. Send calls to the entered number and connect it to an extension 1000 in the system.

$host = “”;
$user = “clicktocall”;
$secret = “password”;
$context = “dial”;
$waitTime = “30”;
$priority = “1”;
$number = $_POST[“number”];
$oSocket = fsockopen($host, 5038, $errnum, $errdesc) or die(“Connection to host failed”);
fputs($oSocket, “Action: loginrn”);
fputs($oSocket, “Events: offrn”);
fputs($oSocket, “Username: $userrn”);
fputs($oSocket, “Secret: $secretrnrn”);
fputs($oSocket, “Action: originatern”);
fputs($oSocket, “Channel: SIP/didforsale/$numberrn”);
fputs($oSocket, “WaitTime: $waitTimern”);
fputs($oSocket, “exten: 1000rn”);
fputs($oSocket, “Context: $contextrn”);
fputs($oSocket, “Async: Truern”);
fputs($oSocket, “Priority: $priorityrnrn”);
fputs($oSocket, “Action: Logoffrnrn”);

Create a dialplan entry now to send calls to extension 1000 in the system when the number answers. Open your /etc/asterisk/extensions.conf file and add the following to it

exten => 1000,1,Dial(SIP/1000)
Same => n,Hangup

Now create your webpage, add a number field in the webpage to enter the number. When someone enters a number in this field, post it to the php script we just created.

That is it and now someone enters a number in the webpage, he will get a call immediately and when he answers the call, extension 1000 will ring and they will get connected.