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.
LVL 1
tripatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ArikaelCommented:
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?
0
tripatAuthor Commented:
exec is enabled I am sure because, in same program I running this:

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

I have tried this:

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

and I get the following output:

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

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

0
nplibCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tripatAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.