PHP--Implement Linux shutdown, restart function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.