D
D
dmitred2018-08-08 16:36:01
linux
dmitred, 2018-08-08 16:36:01

How to restart the server from a PHP script on VPS Centos 7 Jino?

Hello colleagues!
I've been fighting for a whole day I can't figure out the task of restarting the server from the PHP script
Here's what I found and tried on the topic:
1. Add to the file /etc/sudoers:
%www-data ALL=NOPASSWD: /sbin/shutdown
2. Call in php shell_exec('sudo /sbin/shutdown -r now');
It seems to work, but ...
According to point 1, I can't figure out how to use the console I tried to add a line to /etc/sudoers
the editor, but alas, nothing happened, they write everywhere what is visudoneeded through the utility.
I open the file through it, insert a line, press ESC and wq to write, the save message appears and that's it.
I just can’t do a seemingly simple task, tell me, maybe there is some other way to restart from the php script of the server.
Thanks for answers)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Grishin, 2018-08-08
@vesper-bot

What console are you adding from? If from the PHP console, then www-data has no rights to visudo, because it's not fig. You need to prepare everything from under the root, preferably via ssh, and then call as much as you like, but beware of bots, who also like to call anything, anywhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question