0

Hello ladys and gentlemen :)

I got a python script py.py that switches a GPIO (works perfectly when accessing per cmd line).
I got a php file php.php in which I access the py.py file (works perfectly when accessing per cmd line. So the GPIOs got switched). In php.php I got the code echo "test" and I can see test on the terminal.
Furthermore, I am using shell_exec()-command in conjunction with an echo-command to access this py.py. So everything's fine so far.
Now, when I access this php.php per Chromium browser (URL: http://IP-ADRESS/php.php) the browser shows me test, BUT the the GPIOs do NOT switch.

configuration of my Raspberry Pi
First I might tell you that I used a 64GB SD card first. My brother formatted it and installed Raspian the latest version (2020-09-12) on it. So he started configuring the 64GB SD card (unfortunatly he can't remember all of the stuff he did configurating the SD card) and I ended the configuration (but i can't remember all the stuff I looked up on the internet which i put on that linux terminal to configure my Rpi). Finally, everthing worked as we wanted.
Then we bought annother SD card (32GB)(we did not format it, because the internet said there was no need to) and yesterday (2020-09-15) I installed the Raspian imager (latest version) on this SD card. Afterwards I put it into my Rpi and and run the folling commands on my terminal that I found on the internet to configurate it:

turning on VNC sudo raspi-config
installing php7.3 sudo su apt-get update apt-get install php
new root password sudo su passwd
installing MySQL sudo apt-get -y install mariadb-server-10.0 php7.3-mysql mariadb-client-10.0
installing phpmyadmin sudo apt-get install phpmyadmin
concatinate phpmyadmin with apache2 sudo nano /etc/php/7.3/apache2/php.ini adding to the bottom of the file: extension=mysql.so
further commands were sudo mysql -u root -p CREATE USER 'Niklas'@'localhost' IDENTIFIED BY '*password*'; GRANT ALL PRIVILEGES ON *.* TO 'Niklas'@'localhost'; FLUSH PRIVILEGES; then quit
further sudo nano /etc/apache2/apache2.conf and there at the bottom of the file Include /etc/phpmyadmin/apache.conf and saved the file
sudo service apache2 restart .

What I have tried to solve my problem
I can't even remember all instructions I read on the internet to solve the problem, but I' ll try to list most of them right now:
chmod - R in several forms. ls -l on my /var/www/html gives me the following: -rwxrwxrwx 1 Niklas root 544 Sep 15 18:32 py.py etc.
sudo chmod 777 /dev/ttyUSB0 and sudo chmod 777 /dev/ttyAMA0 was something else i saw on the internet to try out, but there is no such dictionary on my SD card (i mean the /dev/ttyUSB0).
sudo chown root:root /var/www/html,
and lastly, I tried the same thing using a .sh-file.

Got an Rpi 3 Model B btw.

Please help me out. I would appriciate it so much :)
Best wiches :)

1
  • 1
    Not pi specific. Read up about Linux permissions.
    – joan
    Sep 16 '20 at 12:12
1

Take running via a web browser by default use the www-data account That is very limited in what it can access for security reasons.

The core security groups that it does not belong to are the gpio i2c spi groups - all used for hardware I/O

A quick fix is to make the www-data user a member of these groups with the usermod command:

sudo usermod -a -G gpio www-data

Be aware that:

  • Getting these commands wrong can stop parts of the system working
  • Changing group (esp on public facing web sites) can open your machine up to security risks
  • Changing group membership can lock you out of the system if you mix up -g and -G or forget the -a

As it is, your site may have issues running as objects for the web site are now in a folder owned by root but they will be owned by www-data or Pi.

Before playing around, read up on security and make a back up of your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.