Page 1 of 1

Error: PHP exec mysql stop

Posted: Tue Sep 11, 2007 7:29 am
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?

Posted: Tue Sep 11, 2007 11:37 am
by Christopher
Maybe the user that the webserver is running as does not have permission to stop that process.

Posted: Tue Sep 11, 2007 12:21 pm
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.

Posted: Tue Sep 11, 2007 12:26 pm
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.

Posted: Tue Sep 11, 2007 12:28 pm
by tomcatf14
Any sample code? I'm noob in PHP...just started PHP 2 weeks back

Posted: Tue Sep 11, 2007 12:29 pm
by volka
There are examples at the sudo site.