Title: reboot raspberry remotly from webserver
Tags: raspbian;ssh;remote;php
Question: I have many raspberries located in different places. All of them are connected to my website and download videos to show on their respective monitors.

Is it possible to send some command from my website (```i use php language```) to reboot the raspberry remotely? That is to say, run a command from my server to reboot a raspberry pi?  

My raspberries are connected to an access point which is connected to the internet, but it does not have static IP.

This guide here presumes the raspberry and the server machine are in the same network, but for my setup that is not true.

Any solution to restart the raspberry remotely (through internet) would be helpful.


Here is the accepted answer: On your webserver you can setup a specific file to hold a command, for example

```http://myserver.com/command-for-raspberry.txt
```

That file should hold a sequence number and a command.

Periodically (research crontab) the Raspberry Pis should download that page, check the sequence number against their saved sequence number of the latest command they run, check the command against a list of valid commands, and if so, execute the command and save the sequence number for future reference.

Then all you have to do is create the file ```command-for-raspberry.txt``` with, for example, the content

```01  reboot now
```

put it on the server and wait for the Pis to download and execute it.

NOTE: there is no security built into this solution, and it can be easily exploited in a multitude of ways.

Comment for this answer: Actually i really started a solution close to your solution.... i create a python script listener.py in my raspberry... it always send a request to a simple web Service in my server... which will give it the command to execute ... for security my python always send a API Key and my web service also check this key ... but i will consider you answer is the best and the correct one ... thank you

Here is another answer: You can install and run piControl, a Node.js web application to shut down or reboot your Raspberry Pi.

More info here.

To make your Raspberry Pi reachable from the Internet, you should give it a static IP address on your local network, and forward the public HTTP default port (80) to the local IP address of the Raspberry Pi.

Comment for this answer: i like piControl but they said "piControl is allow reboot and shutdown from browser in local network" so it is for local network ,,, and you said i must give the pi a static IP ... so how Teamviewer can connect to other PC in windows without static IP ???
Comment for this answer: TeamViewer (TV) is a little special: you don't need your RPi to have a static IP address since when you connect to it, you don't really make a direct connexion from your computer to your RPi. When you run TV on your RPi, the RPi connects to the TV' servers, and waits a incoming connection. Then, when you connect to your RPi from your computer (or tablet, or whatever), your computer will, in fact, connect to the TV' servers, will find your RPi's ID number given by the TV running on your RPi, and take control of your RPi. Besides, you don't need to run TV on the RPi to run piControl.

{'source': 'StackExchangeDataset', 'subset': 'raspberrypi.stackexchange.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:06/11/15', 'FavoriteCount': 2.0, 'PostTypeId': 1, 'Tags': '<raspbian><ssh><remote><php>', 'Title': 'reboot raspberry remotly from webserver', 'ViewCount': 7319, 'id': 32439, 'user_AboutMe': "<p>Computer systems engineer and professional in web development - experience more than seven years and trying to get more.</p>\n\n<p>Through my work with professional teams, I became a very strong in web techniques such as PHP, MYSQL, OOP, CMS, Ajax, JQuery, XML, Web Service ...etc.</p>\n\n<p>My study in Computer Engineering made \u200b\u200bme very nicely for using the concepts of software engineering such as DESIGN PATTERN, OO DESIGN , UML , Agile Methodology ... etc.</p>\n\n<p>No one know every things, so I'm always trying to keep up with the latest technologies and learn them, I love my job so much and hungry to do more in this area.</p>\n\n<p>Specialties: web development , php development , E-commerce development, E-learning system development, Moodle LMS development.</p>\n", 'user_AccountId': 4441115.0, 'user_DisplayName': 'Mohammad Alabed', 'user_Reputation': 123.0, 'user_Views': 10.0, 'user_id': 28083.0}}