3

Encountering a problem when running phpagi:

-- Executing [123@DLPN_C:1] AGI("SIP/1000-00000001", "hello_world.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/hello_world.php
hello_world.php: Failed to execute '/var/lib/asterisk/agi-bin/hello_world.php': Exec format error
-- Auto fallthrough, channel 'SIP/1000-00000001' status is 'UNKNOWN' Scheduling destruction of SIP dialog '343930130' in 32000 ms (Method: INVITE)

From command line:

root@asterisk-test:/var/lib/asterisk/agi-bin# php5 -q hello_world.php 
#!/usr/bin/php5 -q

Additional info:

-rwxr-xr-x  1 root     root       757 Mar 29 19:32 hello_world.php
drwxrwxr-x  4 root     root      4096 Mar 29 19:44 phpagi
-rwxr-xr-x  1 root     root     25079 Sep 30  2010 phpagi-asmanager.php
-rwxr-xr-x  1 root     root      2322 Sep 30  2010 phpagi-fastagi.php
-rwxr-xr-x  1 root     root     67615 Sep 30  2010 phpagi.php

Source of hello world: http://www.eder.us/projects/phpagi/phpagi/api-docs/__examplesource/exsource_home_html_projects_phpagi_phpagi_examples_dtmf.php_acb7257145e4a5249182c8373cd8e848.html

AWippler
  • 417
  • 3
  • 9
  • 16
  • In your source `/usr/local/bin/php` and in your example `/usr/bin/php5`, and what is the `-q` switch? – clover Mar 30 '13 at 00:41
  • Quiet mode. More info here: http://stackoverflow.com/questions/5777792/what-does-it-mean-to-run-php-in-quiet-mode – AWippler Mar 30 '13 at 03:32

4 Answers4

5

The Exec Format Error is from /bin/bash, asterisk executes hello_world.php as a bash script.

shebang

If you add a correct shebang, the script get executed by the given PHP intepreter. The first Line tells the System which program should run the script.

#!/usr/bin/env php

To test your shebang, execute the script itself, not by PHP:
root@asterisk-test:/var/lib/asterisk/agi-bin# ./hello_world.php

Make sure it is executable with:
root@asterisk-test:/var/lib/asterisk/agi-bin# chmod +x hello_world.php

alternative wrapper

Create a bash script that executes the PHP script.

example hello_world.sh:
/usr/bin/php hello_world.php

and call it in the Dialplan AGI("hello_world.sh").

Make sure the shellscript is executable chmod +x hello_world.sh.

pce
  • 5,571
  • 2
  • 20
  • 25
  • ./hello_world.php did not work, but php hello_world.php worked. – AWippler Apr 01 '13 at 16:47
  • `./hello_world.php` must work to get it executed by asterisk, you should adjust the shebang to the binary that is used by php, which you can see by executing `which php` and make sure it is executable. – pce Apr 01 '13 at 17:04
  • I have /usr/bin/php and /usr/bin/php5. php is a link to php5. – AWippler Apr 01 '13 at 19:12
  • try `#!/usr/bin/env php` and is `hello_world.php` executable? I updated my answer, try a alternative wrapper. – pce Apr 01 '13 at 21:41
3

I added following line on top script to get it working for me

#!/usr/bin/php -q
TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
1

You issue is not asterisk issue,but general linux one.

Please try from your command line following:

su asterisk -c "/var/lib/asterisk/agi-bin/hello_world.php"

Most likly reasons: php path is incorrect or selinux enabled and not configured.

arheops
  • 15,544
  • 1
  • 21
  • 27
0

Could you check your extensions.conf or extensions_custom.conf, if the extension and priority are not continuous also this error will occur.

please check the below example:

[context]
exten => 1,1,Answer()
exten => 1,2,AGI(your-agi-script)
exten => 1,3,Hangup()