How to realize the shutdown and restart function of linux by php
This article is about how php implements linux shutdown and restart. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Php to achieve linux shutdown restart function: 1, create a PHP sample file; 2, use PHP to execute linux commands, code statements such as "exec ('/ sbin/reboot');"; 3, add permissions to the restart command.
This article operating environment: linux5.9.8 system, PHP7.1 version, DELL G3 computer
How does php realize the linux shutdown and restart function?
Php realizes linux shutdown and restart function
Sometimes, we can DIY a control panel to implement the shutdown and restart function of linux. As we all know, linux is a file-based operating system, so the shutdown and restart function of the system must meet the following two points
First, know the absolute path of the command
When operating under linux, we can just type in the command. But you can't do this when you execute a linux command with PHP. You need to know the absolute path to the command.
Restart command reboot absolute path / sbin/reboot
Shutdown command shutdown absolute path / sbin/shutdown
Execute the linux command with PHP
There are many functions, which I have introduced in some blog posts before. The exec function is recommended here.