You can not simply run command from php file to Reboot/Shutdown Raspberry Pi as you would from shell and it wouldn’t be very convenient to login to shell and issue Reboot/Shutdown command each time you need to bring reboot or shutdown your Raspberry Pi.

  1. You need to write script that would reboot Raspberry Pi.
  2. Some OS configuration changes to allow the reboot command from web application.
  3. Php page to execute script to shutdown or reboot Raspberry Pi.

Python Script for Reboot Raspberry Pi

Create a python script (i named it reboot.py) See Python Ref for sub-process command.

Python Script for Shutdown Raspberry Pi

Create a python script (i named it shutdown.py) See Python Ref for sub-process command.

OS Configuration Changes

For python code to work fully from web page it must run in the context of a user that has sufficient privileges. Run following command and go to the end of the file and add the following line

Above changes to enable user www-data to use the reboot and shutdown commands, press Ctrl+x to save and Ctro+x to exit.

PHP Side

For PHP – exec() vs system() vs passthru() please refere to this link for more details.