Using PHP with the Asterisk Gateway Interface (AGI)
The shebang should be followed immediately by the
PHP Tips and Examples
Script Location
Asterisk expects to find scripts in the/var/lib/asterisk/agi-bin/
directory for AGI execution.Page Contents
File Permissions
Remember to make your files executable with chmod 755 /var/lib/asterisk/agi-bin/*.php
.The Shebang
The first line in your script will of course determine which executable runs it. Be aware of the different versions of PHP, such as/usr/bin/php
and /usr/bin/php-cgi
. In most cases life will be easier if you use the CLI version— typically at /usr/bin/php
. (Use /usr/bin/php -v
to confirm that you are using the CLI version.) This will make $argv
and $argc
available, disable buffering, disable HTTP header output, and pipe error messages to STDERR instead of STDOUT. All these are desirable for working with Asterisk. If you use the CGI executable, you will have to use some command line options and edit your scripts to ensure proper behaviour.The shebang should be followed immediately by the
<?php
script opener, with only a newline between them. Any whitespace could get sent to Asterisk, causing problems.