0

hi I have a raspberry pi and install apache on this. On my raspberry runs raspian and I want to execute linux prompts about my web. For example I have a webapplication run on this apache and I want to shutdown the raspberry by a click on a button "shutdown". (This is only one method for my application). I build webapplications in php or C# with .NET.

Can I do this and what i must know for this?

I want to build a simple Webapplication for other users.

Tarasov
  • 3,625
  • 19
  • 68
  • 128
  • 2
    possible duplicate of [Shutting down computer from a python script in apache](http://stackoverflow.com/questions/20066583/shutting-down-computer-from-a-python-script-in-apache). Just replace popen with exec if you're using PHP. – Adriano Repetti Dec 02 '13 at 13:42

1 Answers1

0

You can use exec(), system() or passthru() function to execute commands.

For example you can shutdown a linux system with:

<?php
    exec("shutdown -h now");
?>

Make sure the apache user has the permission to execute this command.

Maarkoize
  • 2,601
  • 2
  • 16
  • 34
  • But make sure the PHP-Process has enough rights, because only root have the right to restart the machine. Please also note, that this will create critical security issues and should never be reachable over the internet. – DiableNoir Dec 02 '13 at 14:07
  • That's correct that's why on most webservers these functions are disabled by default. You can make an admin login, correct. But make sure that there is no possibilty to load this site without a login (e.g. SQL Injection) – Maarkoize Dec 02 '13 at 14:08