Writing PHP AGI's

I’m a PHP developer and want to start playing with my asterisk box at work that is powered by a FreePBX admin.

I found a helpful starter tutorial on AGI’s here:

I have a couple of problems though. How do I add extensions to trigger my AGI’s without breaking my FreePBX setup by manually modifying the extensions.conf?

I saw in the comments that these should be put in extensions_custom.conf, which I did, but it seems that on restart, I loose my FreePBX extensions. The only think I modified in extensions.conf was to un-comment the hash infront of the include to extensions_custom.conf. But it dropped my FreePBX extensions, or at least the phones were unreachable until I put re-commented out the include and restarted the machine.

Is there standard way to add your own AGI’s at certain extensions in a FreePBX friendly sort of way?

Any idea what happened there?

The hash in front of extensions_custom.conf is part of the Asterisk syntax, by deleting it you broke the include and stopped parsing the rest of the file.

It would help to have some idea what you are actually trying to do. The procedure would be different if you were trying to trigger an AGI on outgoing calls from a particular extension, as opposed to triggering an AGI on incoming calls to a particular extension. If you just want a custom extension that will do an AGI call and then hang up (for example, get current weather conditions, speak them to the caller, and hang up), you can put something like that entirely in extensions_custom.conf.

If trying to use the sample from the link you provided, that could probably go in extensions_custom.conf also, but it’s probably best to have at least one additional line after any AGI call, plus a hangup context. So:

exten => 5151,1,AGI(test.php)
exten => 5151,n,hangup()
exten => h,1,hangup()

Make sure your PHP file is in /var/lib/asterisk/agi-bin and has similar ownership and permissions to other agi-bin files (in particular, that user and group are both asterisk).

I’ve just started out using PBX in a Flash with FreePBX, so I’ve been blogging what I’ve been doing to make sure I really understand it and to keep a record of how I solved various problems.

While I’m late to the party for this question, I did just write a post on how to modify dial plans under FreePBX. If someone comes across this while searching perhaps it will help them. (I was searching for help on dialing out using PHPAGI, myself, so no joy here for me)