如何通过php脚本执行终端命令

I have a php script that I need to run a linux terminal command. My issue is that I need to run this as sudo but its not working. I have done VISUDO and added / disabled as follows:

asterisk ALL=NOPASSWD: /usr/sbin/cmd.php
Defaults!/usr/sbin/cmd.php !requiretty
#Defaults    requiretty
#Defaults   !visiblepw

But I'm getting this error in apache logs "sudo: no tty present and no askpass program specified". FYI Apache is running as user asterisk and its Centos 6. I'm stuck now so reaching out.

Thanks

Your asterisk account not have shell login. sudo user must have shell login. Check it in /etc/passwd. If nologin, it means thar no access to shell.

You need to check asterisk API, it's call AMI (Asterisk Management Interface) https://github.com/marcelog/PAMI