I am trying to use PHP to reload the extensions in an Asterisk installation. I keep getting this error: Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) when I run the script by visiting the URL; however, if I run the script from the command line, it runs just fine (works perfect, actually). I think it is permissions related. Does anyone have any ideas? <php $output = shell_exec('asterisk -rx"extensions reload"'); echo $output; ?> Yours, Michael Munger, dCAP 404-438-2128 michael at highpoweredhelp.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20071003/6362dd78/attachment.htm
Michael Munger wrote:> I am trying to use PHP to reload the extensions in an Asterisk > installation. I keep getting this error: > > Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) > when I run the script by visiting the URL; however, if I run the script > from the command line, it runs just fine (works perfect, actually). > > I think it is permissions related. Does anyone have any ideas? > > <php > $output = shell_exec('asterisk -rx"extensions reload"'); > echo $output; > ?> >I'm not a PHP guy, but shouldn't the double quote be surrounding the entire shell command like this? $output = shell_exec('"asterisk -rx extensions reload"'); Lee
Michael Munger wrote:> I am trying to use PHP to reload the extensions in an Asterisk > installation. I keep getting this error: > > Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) > when I run the script by visiting the URL; however, if I run the script > from the command line, it runs just fine (works perfect, actually). > > I think it is permissions related. Does anyone have any ideas? > > <php > $output = shell_exec('asterisk -rx"extensions reload"'); > echo $output; > ?>I guess your web server does not run as root and thus is not allowed to invoke asterisk. (Try echo shell_exec('id'); or echo get_current_user(); in PHP.) A possible solution (although not nice): Add www-data ALL=(ALL) NOPASSWD: ALL to /etc/sudoers (depending on your distribution etc. the Apache user might be www-data / apache / ...) and in the PHP script run shell_exec('sudo asterisk -rx "extensions reload"'); Regards, Philipp Kempgen -- amooma GmbH - Bachstr. 126 - 56566 Neuwied - http://www.amooma.de Let's use IT to solve problems and not to create new ones. Asterisk? -> http://www.das-asterisk-buch.de My pick of the month: rfc 2822 3.6.5 Gesch?ftsf?hrer: Stefan Wintermeyer Handelsregister: Neuwied B 14998
Michael Munger wrote:> > I am trying to use PHP to reload the extensions in an Asterisk > installation. I keep getting this error: > > Unable to connect to remote asterisk (does /var/run/asterisk.ctl > exist?) when I run the script by visiting the URL; however, if I run > the script from the command line, it runs just fine (works perfect, > actually). > > I think it is permissions related. Does anyone have any ideas? > > <php > $output = shell_exec('asterisk -rx"extensions reload"'); > echo $output; > ?> > > > > Yours, > > Michael Munger, dCAP > > 404-438-2128 > > michael at highpoweredhelp.com <mailto:michael at highpoweredhelp.com> > > >If running a script from a browser, it is usually run as "nobody", from the command line it is whatever user you are, probably root. Thanks, Steve Totaro
If you are running the script from a web server, the script gets executed with the web server process permissions, hence, probably does not have access to /var/run/asterisk.ctl. You can give permissions to your web server, or better yet, dont execute the command using shell_exec, better open a socket connection to the Asterisk manager and execute Action: Command Command: extensions reload Regards On 10/3/07, Michael Munger <michael at highpoweredhelp.com> wrote:> > > > > I am trying to use PHP to reload the extensions in an Asterisk installation. > I keep getting this error: > > Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) > when I run the script by visiting the URL; however, if I run the script from > the command line, it runs just fine (works perfect, actually). > > I think it is permissions related. Does anyone have any ideas? > > <php > $output = shell_exec('asterisk -rx"extensions reload"'); > echo $output; > ?> > > > > Yours, > > Michael Munger, dCAP > > 404-438-2128 > > michael at highpoweredhelp.com > > > _______________________________________________ > --Bandwidth and Colocation Provided by http://www.api-digital.com-- > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > > http://lists.digium.com/mailman/listinfo/asterisk-users >-- "Within C++, there is a much smaller and cleaner language struggling to get out."