• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 885
  • Last Modified:

Restarting MySQL using PHP Script

I am writting a script to restart mysql at a certain check, but I am unable to run the following from PHP:

exec('/sbin/service mysqld restart');

/sbin/service mysqld restart, when run from SSH succussfully restarts mySQL.

Please help me, if I am doing any mistake and correct me.

Do we have to give any permissions to this file, as presently this file is owned by a user not root.
  • 3
1 Solution
Maybe exec is disabled in php.ini?
Search for "disable_functions" in php.ini and check if exec is disabled

Do you get an error message?
tripatAuthor Commented:
exec is enabled I am sure because, in same program I running this:

exec('uptime') and caculating load average from this.
tripatAuthor Commented:

I have tried this:

exec('/sbin/service mysqld restart ',$output);

and I get the following output:

    [0] => Shutting down MySQL...................................[FAILED]
    [1] => Starting MySQL[  OK  ]

does it mean PHP does not have rights to execute this command?

to restart a service it needs root privs.

you would either have to setup what ever is running this php script, like apache to use root instead of wwwuser or whatever it's using.
tripatAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now