swapneelgolapkar
Posts: 1
Joined: Thu Jun 25, 2015 7:40 am

Shutdown Pi using PHP

Sun Jul 12, 2015 3:30 pm

I have made automation app to control lights at my office.
I have used the RPi & to control the setup over wifi I have used php.
I am using it only on wifi & not via internet, I want to create a shutdown button which I am unable to.
I am using the following php code
system("sudo shutdown now")


But its not working.

I googled some solutions but it was using python approach, which I dont want to.
Is there any other solution or something that I am missing.
Experts plz help.

Thanks & Regards
Swapneel

chris57100
Posts: 522
Joined: Wed Sep 12, 2012 7:23 pm
Location: Thionville
Contact: Website

Re: Shutdown Pi using PHP

Mon Jul 13, 2015 8:02 am

Hi
Sounds that the user used to run PHP has no right to execute UNIX root commands wich is a very good configuration.
If you are sure about what you are doing with your pi, find the user running PHP, add it in the sudo users (give to the user the right to run shutdown only) and you will be able to execute the shutdown command within a PHP script

Another way could be to create an empty file some where with the PHP command and a cron script executed as root will check if the file exists. If yes then it will halt/reboot your pi
Raspberry Pi Home Server : http://www.pihomeserver.fr
Software and electronic tutorials : Samba, Airplay, CUPS, Time machine, Nginx, Owncloud, rTorrent, Wordpress, etc.
Full Wi-Fi hotspot installation on a RPi 3 including a captive portal and freeradius management: https://github.com/pihomeserver/Kupiki-Hotspot-Script

Return to “Beginners”