2

I'm trying to execute an Asterisk client command with PHP, to display with html. I used to do it normally. When the server was rebooted, I used to give 777 permissions to the file "/var/run/asterisk/asterisk.ctl" and then I could run a command and display it with PHP and HTML.

Now, I do all those steps, but when I try to display a command, nothing is shown, and Asterisk does not return any message. The command that I try to execute with PHP is:

exec('sudo asterisk -rx "sip show peers"',$data);

The variable $data returns nothing.

leirbag
  • 73
  • 1
  • 3
  • 8
  • 1
    Anything in asterisk console? eg. in `asterisk -r` – S.I. Oct 25 '16 at 14:41
  • did you grant password-less sudo rights to your webserver's uid? if so, sudo's probably whining about the lack of a terminal. And you'll probably want to redirect stderr, because `$data` will only contain stdout. – Marc B Oct 25 '16 at 14:42
  • sudo commands normally prompt for a password. You could edit the sudoers file (with visudo) and add a rule that allows the web server user to run the command without a password. For example: www-data ALL=NOPASSWD: /path/to/script – Duane Lortie Oct 25 '16 at 14:44

2 Answers2

0

I think first you have check is "what is path for your apache account".

It is really unlikly apache see /usr/sbin/. So you need use full path to asterisk

Second thing you have check - if your sudo(/etc/sudoers) REALLY allow run asterisk for apache(or nobody, depend of your setup) user.

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

Finally I could solve it. It remained an issue of permissions. Apparently, you can't use the pre-command "sudo". So I removed it, and the online users console reappeared in PHP.

Thanks for your help!

leirbag
  • 73
  • 1
  • 3
  • 8