Error: PHP exec mysql stop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomcatf14
Forum Newbie
Posts: 11
Joined: Wed Sep 05, 2007 3:33 pm

Error: PHP exec mysql stop

Post by tomcatf14 »

My script look as below:-

Code: Select all

<?php
$output = shell_exec('/usr/local/etc/rc.d/mysql-server stop');
echo "<pre>$output</pre>";
?>
The result:
mysql not running? (check /var/db/mysql/v3b.dnsvine.com.pid).

If i run "/usr/local/etc/rc.d/mysql-server stop" on the server, mysql could be stopped fine. What is wrong?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Maybe the user that the webserver is running as does not have permission to stop that process.
(#10850)
tomcatf14
Forum Newbie
Posts: 11
Joined: Wed Sep 05, 2007 3:33 pm

Post by tomcatf14 »

I have created a script own by root with permission 777 to run mysql restart but still not able to solve the problem.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The owner alone doesn't matter, the script is still executed with the permissions of the process that is running your php script.
You need at least the setuid flag. Or even better configure sudo to allow the webaccount to restart the mysql server.
Last edited by volka on Tue Sep 11, 2007 12:28 pm, edited 1 time in total.
tomcatf14
Forum Newbie
Posts: 11
Joined: Wed Sep 05, 2007 3:33 pm

Post by tomcatf14 »

Any sample code? I'm noob in PHP...just started PHP 2 weeks back
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

There are examples at the sudo site.
Post Reply