Raspberry Pi PHP shell commands

L I V E Stammtisch ab 20:30 Uhr im Chat
  • Hallo Zusammen,

    ich habe zu dem Thema schon einiges gefunden, hatte allerdings bisher noch keinen Erfolg. Aus diesem Grund schreibe ich hier aus Verzweiflung obwohl es sicherlich ein recht triviales Problem ist.

    Folgendes:

    Über NGINX habe ich einen Server laufen über den ich einen Versuchsaufbau mittels Webcam beobachte. Zum ein uns Ausschalten der Stromversorgung würde ich gerne über die Weboberfläche einen GPIO ein und ausschalten. Alles nur im lokalen Netz deshalb auch nicht streng sicherheitsrelevant. Über PHP möchte ich als Shell command also einen GPIO setzen/rücksetzen.

    Ich habe bisher ausprobiert:

    über WiringPi und einem Shell command den GPIO initialisieren und setzen. Dem Server www-data habe ich dafür die benötigten Rechte gegeben. PHP ist auch in NGINX installiert, konfiguriert und getestet. Leider passiert aber einfach nichts.

    In den logs von PHP habe ich auch schon gesucht, da steht aber nichts drin geschrieben und mangels Erfahrung weiß ich auch nicht so recht wonach ich suchen muss.:helpnew:

    Hier mal genauer was ich tuen möchte:

  • Genau, an dieses Tutorial habe ich mich orientiert. Ich habe alle Schritte wie beschrieben vorgenommen.

    Sprich;

    1 sudo chmod g+s /var/www


    2 sudo chmod 775 /var/www


    3 sudo chown -R www-data:www-data /var/WWW

    als es dann immer noch nicht funktionierte habe ich

    www-data ALL=NOPASSWD: ALL 

    in der sudoers Datei unten angefügt.

    Liegt das Problem vielleicht bei NGINX? PHP funktioniert da wie gesagt aber. Das schalten der GPIOs funktioniert aus der Konsole heraus auch mit pi als auch WWW-data als user. Das ganze klappt bei beiden auch ohne sudo vorgesetzt.

  • Hier mal ein Ausschnitt aus der error.log vom NGINX:

    2020/12/04 08:20:16 [error] 591#591: *32 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?Lichtein=Licht+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/"

    2020/12/04 08:20:17 [error] 591#591: *32 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?Lichtaus=Licht+aus HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?Lichtein=Licht+ein"

    2020/12/04 08:20:19 [error] 591#591: *32 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?Lichtein=Licht+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?Lichtaus=Licht+aus"

    2020/12/04 08:20:20 [error] 591#591: *32 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?Lichtaus=Licht+aus HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?Lichtein=Licht+ein"

    2020/12/04 08:29:40 [error] 590#590: *67 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?Lichtaus=Licht+aus HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?Lichtaus=Licht+aus"

    2020/12/04 08:29:41 [error] 590#590: *67 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?Lichtein=Licht+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?Lichtaus=Licht+aus"

    2020/12/04 08:29:42 [error] 590#590: *67 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?Lichtaus=Licht+aus HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?Lichtein=Licht+ein"

    2020/12/04 08:42:54 [error] 590#590: *113 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?on=Spannungsversorgung+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?Lichtaus=Licht+aus"

    2020/12/04 08:42:54 [error] 590#590: *113 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?off=Spannungsversorgung+aus HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?on=Spannungsversorgung+ein"

    2020/12/04 08:42:56 [error] 590#590: *113 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?on=Spannungsversorgung+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?off=Spannungsversorgung+aus"

    2020/12/04 08:50:33 [error] 590#590: *137 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?on=Spannungsversorgung+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?on=Spannungsversorgung+ein"

    2020/12/04 08:50:34 [error] 590#590: *145 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?off=Spannungsversorgung+aus HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?on=Spannungsversorgung+ein"

    2020/12/04 08:52:09 [error] 590#590: *145 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?on=Spannungsversorgung+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?off=Spannungsversorgung+aus"

    2020/12/04 08:52:10 [error] 590#590: *154 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 102" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?off=Spannungsversorgung+aus HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?on=Spannungsversorgung+ein"

    2020/12/04 08:52:12 [error] 590#590: *154 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?on=Spannungsversorgung+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?off=Spannungsversorgung+aus"

    2020/12/04 08:52:13 [error] 590#590: *154 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?on=Spannungsversorgung+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?on=Spannungsversorgung+ein"

    2020/12/04 08:52:13 [error] 590#590: *154 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?on=Spannungsversorgung+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?on=Spannungsversorgung+ein"

    2020/12/04 08:52:42 [error] 590#590: *159 FastCGI sent in stderr: "PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99PHP message: PHP Warning: A non-numeric value encountered in /var/www/html/index.php on line 99" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php?on=Spannungsversorgung+ein HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169", referrer: "http://192.7.100.169/index.php?on=Spannungsversorgung+ein"

    2020/12/04 08:58:57 [error] 591#591: *183 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '/' in /var/www/html/index.php on line 83" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169"

    2020/12/04 08:59:05 [error] 591#591: *183 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '/' in /var/www/html/index.php on line 83" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169"

    2020/12/04 08:59:10 [error] 591#591: *183 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '/' in /var/www/html/index.php on line 83" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169"

    2020/12/04 08:59:29 [error] 591#591: *183 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '/' in /var/www/html/index.php on line 83" while reading response header from upstream, client: 192.7.100.44, server: _, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "192.7.100.169"

  • Lagere doch mal den Teil in eine an.sh aus, also

    trim(@shell_exec("/var/www/html/an.sh"));

    Bash
    #!/bin/bash
    /usr/local/bin/gpio -g write 17 1

    Dann nochmal probieren.

    Die Fehlermeldung irritiert, da dein Script nur 15 Zeilen hat.

    Habe ich getan, leider immer noch ohne Erfolg.

    Die Fehlermeldung stammt von früher am Tag. Da ich viel ausprobiert habe, war da wohl der Code noch etwas anders. Weiter unten in der error.log Datei kommen aber leider keine weiteren Meldungen mehr bzgl. PHP.

    So langsam verzweifle ich. Das kann doch kein Hexenwerk sein.

  • Bist du auch sicher, dass der richtige GPIO geschaltet wird ?

    Lässt sich ja mit gpio readall herausfinden.

    Zitat

    Zuerstmal muss man wissen, dass die Belegung der GPIO’s unter Verwendung von WiringPi anderst ist. So ist z.B der GPIO 17 in WiringPi GPIO0 und der GPIO18 in WiringPi GPIO1.

    Ich sehe keinen GPIO 17 bei WiringPi.

  • Beim ausführen der bash Anweisung wurde mir folgender Fehler angezeigt:

    pi@raspberrypi:/var/www/html $ bash init.sh

    init.sh: line 3: /usr/local/bin/gpio: No such file or directory

    Ich habe die .sh jetzt mal so abgewandelt (siehe unten) und jetzt kann ich sie immerhin aus der Konsole ausführen.

    Bash
    #!/bin/bash
    
    gpio -g mode 17 out
    • Offizieller Beitrag

    als es dann immer noch nicht funktionierte habe ich

    www-data ALL=NOPASSWD: ALL

    in der sudoers Datei unten angefügt.

    Wieder dieser gefährliche Unsinn! :no_sad: Mach das bitte rückgängig!

    Falls es danach nicht mehr funktionieren sollte, dann schubs den www-data in die Gruppe gpio.

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!