homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

shell exec problem. Any help?
issuing service restart command using shell_exec

Msg#: 4149430 posted 7:10 am on Jun 9, 2010 (gmt 0)

I'm trying to restart bind of my server using php
The commands I generally use with putty are:
service named restart
/etc/init.d/named restart
Both work fine.

When I used "any" of those commands with php like:
<?php echo shell_exec("/etc/init.d/named restart"); ?>
I get this output:

Stopping named......[failed]
Starting named named: already running....[failed]

What am I missing here?

I also changed the owner and group of this php script using putty
chown root:root /home/site/rn.php

but it still does the same.

Is it possible to do this using a sh script? If so, please give me the code I need to use in the script. I don't know how to use sh scripts...
Thank you



WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4149430 posted 8:39 pm on Jun 10, 2010 (gmt 0)

is it maybe because the user running php might have permissions issues?


WebmasterWorld Senior Member 5+ Year Member

Msg#: 4149430 posted 8:12 pm on Jun 12, 2010 (gmt 0)

Just a note, the two following are identical functionally

$something = shell_exec("/etc/init.d/named restart");
$something = `/etc/init.d/named restart`;

(Note that I used backticks - not single quotes

Quite a neat little snippet I think :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved