PHPAGI: Exec format error

11,765

Solution 1

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.

Solution 2

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

#!/usr/bin/php -q

Solution 3

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.

Share:
11,765
AWippler
Author by

AWippler

Updated on August 07, 2022

Comments

  • AWippler
    AWippler over 1 year

    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
    AWippler about 11 years
    ./hello_world.php did not work, but php hello_world.php worked.
  • pce
    pce about 11 years
    ./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.
  • arheops
    arheops about 11 years
    check that you have /usr/bin/text2wave and it is exutable.
  • AWippler
    AWippler about 11 years
    I do. text2wave --help text2wave [options] textfile Convert a textfile to a waveform
  • AWippler
    AWippler about 11 years
    I have /usr/bin/php and /usr/bin/php5. php is a link to php5.
  • pce
    pce about 11 years
    try #!/usr/bin/env php and is hello_world.php executable? I updated my answer, try a alternative wrapper.
  • arheops
    arheops about 11 years
    have you checked selinux? have you tried DISABLE it? that vary depend of your OS, usualy /etc/sysconfig/selinux (need restart after change)
  • AWippler
    AWippler about 11 years
    The host is debian. SELinux is not enabled.
  • arheops
    arheops about 11 years
    try do following: 1) stop asterisk. 2) start it using "asterisk -vvvc" 3) agi set debug on, 4) re-check output.