Sometimes, we can DIY a control panel to implement the Linux shutdown restart function. As we all know, Linux is a file-based operating system, so to implement the system shutdown restart function must meet the following two points
First, know the absolute path of the command
When operating under Linux, we directly typed in the command. However, it is not possible to execute a Linux command with PHP, and you need to know the absolute path of the command.
Restart command reboot absolute path/sbin/reboot
Shutdown command shutdown absolute path/sbin/shutdown
Second, execute Linux commands with PHP
There are many functions that I have previously introduced. It is recommended to use the EXEC function.
<?php/** * PHP executes linux command *///returns command execution result, note command to write absolute path exec ('/sbin/reboot ');
Third, add permissions to the restart command
Linux permissions performance is very delicate, the default reboot permissions can only root, want PHP to perform shutdown can only give reboot command appropriate permissions
Method One: Add the Nginx/apache Action Group to a management group, such as the web. Then add reboot to the admin group and give the G plus x command
Mode two: direct chmod 4777/sbin/reboot return to fix, but not recommended, because this is equal to all users have restart permission.
PHP--Implement Linux shutdown, restart function