问题
I would like to create a button on my website that restarts mysql (I realize this is really bad news). I am using ec2 which has really strict user permissions.
This is my php code, but it's not restarting the session.
<?php
if(isset($_POST['mysql'])){
exec("sudo /etc/init.d/mysqld restart");
}
?>
<form method="POST" action="">
<input type="submit" value="mysql" name="mysql">
</form>
This is my suders file ...
Cmnd_Alias RESTART_MYSQL = /etc/init.d/mysqld restart
mysql ALL =NOPASSWD: RESTART_MYSQL
This doesn't work either...
Cmnd_Alias RESTART_MYSQL = /etc/init.d/mysqld restart
apache ALL =NOPASSWD: RESTART_MYSQL
回答1:
When you run sudo, you need to enter your password. SO, you can't use sudo in a script.
来源:https://stackoverflow.com/questions/10588636/restart-mysql-within-php-browser-permissions-issue