Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3843

General discussion • Re: PHP Calling Pinctrl in shell_exec different in browser from command line

$
0
0
On Bookworm 64-bit on a Pi5 8GB, user pi, this works for me (may not be that secure) using pinctrl and php:

Code:

<!DOCTYPE html><html><head><meta charset="UTF-8" /></head><body><?phpif(isset($_POST["on"])) {$result=shell_exec('pinctrl set 21 op dh');}if(isset($_POST["off"])) {$result=shell_exec('pinctrl set 21 op dl');}?>Test using pinctrl GPIO21<br><form method="POST">  <input type="submit" value="On" name="on" /><p>  <input type="submit" value="Off" name="off" /></form></body></html
Note I have modified the apache2 file ownership

Code:

sudo chown -R pi:www-data /var/wwwsudo chmod u+rxw,g+rx-w,o-rwx /var/wwwsudo chmod g+s /var/www
and restarted apache2
user and group of index.php:

Code:

pi@pi64bk:/var/www/html $ ls -lah-rw-r--r-- 1 pi www-data  394 Feb 20 10:14 index.php
Did you forget to mention that you added user www-data to the group gpio and actually this made it work?

Code:

pi@headless-pi:~ $ groups www-datawww-data : www-datapi@headless-pi:~ $ sudo -u www-data pinctrlMust be rootpi@headless-pi:~ $ sudo adduser www-data gpioAdding user `www-data' to group `gpio' ...Done.pi@headless-pi:~ $ groups www-datawww-data : www-data gpiopi@headless-pi:~ $ sudo -u www-data pinctrl 0: ip    pu | hi // ID_SDA/GPIO0 = input 1: ip    pu | hi // ID_SCL/GPIO1 = input 2: ip    pu | hi // SDA1/GPIO2 = input 3: ip    pu | hi // SCL1/GPIO3 = input 4: ip    pu | hi // GPIO_GCLK/GPIO4 = input 5: ip    pu | hi // GPIO5 = input 6: ip    pu | hi // GPIO6 = input 7: ip    pu | hi // SPI_CE1_N/GPIO7 = input 8: ip    pu | hi // SPI_CE0_N/GPIO8 = input 9: ip    pd | lo // SPI_MISO/GPIO9 = input10: ip    pd | lo // SPI_MOSI/GPIO10 = input11: ip    pd | lo // SPI_SCLK/GPIO11 = input12: ip    pd | lo // GPIO12 = input13: ip    pd | lo // GPIO13 = input14: ip    pn | hi // TXD1/GPIO14 = input15: ip    pu | hi // RXD1/GPIO15 = input16: ip    pd | lo // GPIO16 = input17: ip    pd | lo // GPIO17 = input18: ip    pd | lo // GPIO18 = input19: ip    pd | lo // GPIO19 = input20: ip    pd | lo // GPIO20 = input21: ip    pd | lo // GPIO21 = input22: ip    pd | lo // GPIO22 = input23: ip    pd | lo // GPIO23 = input24: ip    pd | lo // GPIO24 = input25: ip    pd | lo // GPIO25 = input26: ip    pd | lo // GPIO26 = input27: ip    pd | lo // GPIO27 = input28: a5    pu | hi // RGMII_MDIO/GPIO28 = RGMII_MDIO29: a5    pd | lo // RGMIO_MDC/GPIO29 = RGMII_MDC30: a3    pu | lo // CTS0/GPIO30 = CTS031: a3    pn | lo // RTS0/GPIO31 = RTS032: a3    pn | hi // TXD0/GPIO32 = TXD033: a3    pu | hi // RXD0/GPIO33 = RXD034: ip    pu | hi // SD1_CLK/GPIO34 = input35: ip    pu | hi // SD1_CMD/GPIO35 = input36: ip    pu | hi // SD1_DATA0/GPIO36 = input37: ip    pu | hi // SD1_DATA1/GPIO37 = input38: ip    pu | hi // SD1_DATA2/GPIO38 = input39: ip    pu | hi // SD1_DATA3/GPIO39 = input40: a0    pn | lo // PWM0_MISO/GPIO40 = PWM1_041: a0    pn | lo // PWM1_MOSI/GPIO41 = PWM1_142: op -- pu | lo // STATUS_LED_G_CLK/GPIO42 = output43: ip    pu | hi // SPIFLASH_CE_N/GPIO43 = input44: ip    pu | hi // SDA0/GPIO44 = input45: ip    pu | hi // SCL0/GPIO45 = input46: ip    pu | lo // RGMII_RXCLK/GPIO46 = input47: ip    pu | lo // RGMII_RXCTL/GPIO47 = input48: ip    pd | lo // RGMII_RXD0/GPIO48 = input49: ip    pd | lo // RGMII_RXD1/GPIO49 = input50: ip    pd | lo // RGMII_RXD2/GPIO50 = input51: ip    pd | lo // RGMII_RXD3/GPIO51 = input52: ip    pd | lo // RGMII_TXCLK/GPIO52 = input53: ip    pd | lo // RGMII_TXCTL/GPIO53 = inputpi@headless-pi:~ $ sudo deluser www-data gpioRemoving user `www-data' from group `gpio' ...Done.pi@headless-pi:~ $ sudo -u www-data pinctrlMust be rootpi@headless-pi:~ $

Statistics: Posted by fbe — Thu Feb 22, 2024 9:20 pm



Viewing all articles
Browse latest Browse all 3843

Trending Articles