Agi Permission Denied

Hi Guys,

I am sitting with the following problem and don’t really know what I am doing wrong here.
I want to execute a PHP file from the dialplan, but keep getting a permission denied error.

    -- Launched AGI Script /var/lib/asterisk/agi-bin/test.php
 /var/lib/asterisk/agi-bin/test.php: Failed to execute '/var/lib/asterisk/agi-bin/test.php': Permission denied

My dialplan;
same => n,AGI(/var/lib/asterisk/agi-bin/test.php)

I set the user for the file and permissions but seems like still not working.

-rwxrwxrwx 1 asterisk asterisk 240 12月 5 11:26 test.php

The PHP file has just a simple send email function to see if the PHP file is executed.
When I run the PHP file with

php -f /var/lib/asterisk/agi-bin/test.php

It works like a charm, but with the dialplan it doesn’t.

What could be the right solution for this?
I really don’t know anymore what I am doing wrong.
Have tried so many things now.

Thank you


If I set Agi Debud on I get the following.

    -- Launched AGI Script /var/lib/asterisk/agi-bin/test.php
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_request: /var/lib/asterisk/agi-bin/test.php
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_channel: SIP/marshalai_1_999999_1-00000002
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_language: ja
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_type: SIP
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_uniqueid: 1543977852.2
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_version: 13.11.0-rc1
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_callerid: marshalai_1_999999_1
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_calleridname: unknown
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_callingpres: 0
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_callingani2: 0
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_callington: 0
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_callingtns: 0
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_dnid: marshalai_1_999999_2
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_rdnis: unknown
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_context: ctx_marshal-i
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_extension: marshalai_1_999999_2
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_priority: 3
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_enhanced: 0.0
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_accountcode: 
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> agi_threadid: 139809896789760
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> 
<SIP/marshalai_1_999999_1-00000002>AGI Rx << verbose "Failed to execute '/var/lib/asterisk/agi-bin/test.php': Permission denied" 1
 /var/lib/asterisk/agi-bin/test.php: Failed to execute '/var/lib/asterisk/agi-bin/test.php': Permission denied
<SIP/marshalai_1_999999_1-00000002>AGI Tx >> 200 result=1

Set permission 777 for test.php.

755 permision must work as far as you have permision to the directory and the file, also make sure the script it is not executing any function who require root permission

I have tried 777 and 755 permission for the file.
Both keep saying the following.

 Launched AGI Script /var/lib/asterisk/agi-bin/test.php
 /var/lib/asterisk/agi-bin/test.php: Failed to execute '/var/lib/asterisk/agi-bin/test.php': Permission denied

Even if I would say in the PHP file for example

echo 'hello world';

It still keeps saying permission denied.
It looks like somewhere something is going wrong.

Have checked and selinus is disabled.
Any body suggestions what could be the problem for this?

Either SELinux or a permission restriction on a directory.

Not that setting mode 777 on a script is a very bad idea and some programs will refuse to run such scripts.


Try to run a “su - asterisk” and check if you can run the script with the asterisk user.

I fix the problem.
It chmod the file, but I also needed to chmod the folders before the file.

This was causing the permission denied.
Thank you guys. Help was highly appreciated.


I told you that in a previous reply

You are right, can’t believe I read over that.
Wasted a whole day. Thank you for the help.

1 Like