简体   繁体   中英

failed to execute a php script in AGI asterisk, No such file or directory

i am using AGI(Asterisk Gateway Interface) for run php script from dial plan

my dialplan look like

exten =>2600,1,Playback(hello-world)

same =>n,AGI(agiscript.php)

same =>n,Hangup()

agiscript.php is look like

`#!/usr/bin/php -q 
<?php
require_once('dbconnect.php');
db_connect();
$sql = "update oicall_main set balance='100' where username='100';";
$result = mysql_query($sql);
?>`

cli output of agi set debug on is

 ` -- <SIP/example-00000001> Playing 'hello-world.gsm' (language 'en')
    -- Executing [2600@demo:2] AGI("SIP/example-00000001", "agiscript.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/agiscript.php
<SIP/example-00000001>AGI Tx >> agi_request: agiscript.php
<SIP/example-00000001>AGI Tx >> agi_channel: SIP/example-00000001
<SIP/example-00000001>AGI Tx >> agi_language: en
<SIP/example-00000001>AGI Tx >> agi_type: SIP
<SIP/example-00000001>AGI Tx >> agi_uniqueid: 1435426730.1
<SIP/example-00000001>AGI Tx >> agi_version: 13.2.0
<SIP/example-00000001>AGI Tx >> agi_callerid: example
<SIP/example-00000001>AGI Tx >> agi_calleridname: unknown
<SIP/example-00000001>AGI Tx >> agi_callingpres: 0
<SIP/example-00000001>AGI Tx >> agi_callingani2: 0
<SIP/example-00000001>AGI Tx >> agi_callington: 0
<SIP/example-00000001>AGI Tx >> agi_callingtns: 0
<SIP/example-00000001>AGI Tx >> agi_dnid: 2600
<SIP/example-00000001>AGI Tx >> agi_rdnis: unknown
<SIP/example-00000001>AGI Tx >> agi_context: demo
<SIP/example-00000001>AGI Tx >> agi_extension: 2600
<SIP/example-00000001>AGI Tx >> agi_priority: 2
<SIP/example-00000001>AGI Tx >> agi_enhanced: 0.0
<SIP/example-00000001>AGI Tx >> agi_accountcode: 
<SIP/example-00000001>AGI Tx >> agi_threadid: 140718795228928
<SIP/example-00000001>AGI Tx >> 
<SIP/example-00000001>AGI Rx << verbose "Failed to execute '/var/lib/asterisk/agi-bin/agiscript.php': No such file or directory" 1
 agiscript.php: Failed to execute '/var/lib/asterisk/agi-bin/agiscript.php': No such file or directory
<SIP/example-00000001>AGI Tx >> 200 result=1`

这意味着文件包含其他文件或库,无法从此目录访问(可能未使用完整路径)

Either php-cli or php-mysql or both are missing. Install them and reload asterisk.

For CentOS:

sudo yum install php-cli php-gd php-mysql

For Ubuntu/Debian:

sudo apt-get install php-cli php-gd php-mysql

On Centos it worked fine. You need to make sure on asterisk.conf the path is correctly listed pointing to that folder astagidir => /usr/share/asterisk/agi-bin as your default agi-bin folder. Also de dependencies need to be there. I have tried other linux versions and I had the same problem. Make sure you can run php -v from shell otherwise on your php program use php-cli in your header instead of #!/usr/bin/php. One last thing, need to add PATH correctly so it will run from anywhere, otherwise you need to use full path on your extensions.conf (calling your php script full path /var/lib/asterisk/agi-bin/agiscript.php in order for it to process with asterisk CLI set to debug on to see if it does find it. Its a pain, but once it does work, its great.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM