boylesg
Posts: 39
Joined: Fri Jan 15, 2016 3:23 pm

PHP exec() not working as expected

Sat Jun 25, 2016 4:34 pm

I have installed apache on my RPi.

And I have a very simple php web page.

All I am doing is calling exec("python StartCamera.py", $arrayOutput, $nReturn); and then echoing the results.

All I get is 255.

I should be getting an error message because the camera is not connected.

If I run this code in Python3 then I get a very verbose error message.

What is that I have to do to see the same error message on my web page?

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: PHP exec() not working as expected

Sat Jun 25, 2016 4:45 pm

Looks like you are getting the return code from your exec() call.

Can you post the code from the entire page? (Use the

Code: Select all

[/b] blocks if you please.)
Account Inactive

boylesg
Posts: 39
Joined: Fri Jan 15, 2016 3:23 pm

Re: PHP exec() not working as expected

Sat Jun 25, 2016 5:16 pm

SonOfAMotherlessGoat wrote:Looks like you are getting the return code from your exec() call.

Can you post the code from the entire page?
I just noticed a typo in my code "print_r($rrayOutput);" instead of "print_r($arrayOutput);"
But I fixed it as below and now I get "Array ( [0] => * failed to open vchiq instance ) 255" on my web page.

Code: Select all

<?php
     $strCmd = "python StartCamera.py";
     $arrayOutput = array();
     $nReturn - 0;
     exec($strCmd, $arrayOutput, $nReturn);
     echo "<br><br>";
     print_r($arrayOutput);
     echo "<br>"  + $nReturn + "<br><br>";
?>

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: PHP exec() not working as expected

Sat Jun 25, 2016 5:28 pm

boylesg wrote: now I get "Array ( [0] => * failed to open vchiq instance ) 255" on my web page.
Isn't that due to whatever user is running the code isn't part of the video group?

boylesg
Posts: 39
Joined: Fri Jan 15, 2016 3:23 pm

Re: PHP exec() not working as expected

Sat Jun 25, 2016 5:31 pm

stderr wrote:
boylesg wrote: now I get "Array ( [0] => * failed to open vchiq instance ) 255" on my web page.
Isn't that due to whatever user is running the code isn't part of the video group?
You tell me - I am new to doing web pages on Raspberry Pi.

How do I fix it?

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: PHP exec() not working as expected

Sat Jun 25, 2016 6:37 pm

Possibly you need to add the user that the webserver is executing your python as into the video group.
Account Inactive

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: PHP exec() not working as expected

Sat Jun 25, 2016 7:41 pm

boylesg wrote:
stderr wrote:
boylesg wrote: now I get "Array ( [0] => * failed to open vchiq instance ) 255" on my web page.
Isn't that due to whatever user is running the code isn't part of the video group?
You tell me - I am new to doing web pages on Raspberry Pi.
How do I fix it?
I could guess that it is probably the same as whatever the thing is that you are calling it from. But can you run your python code and save things to a file you can look at? Because you could run a python command that said whatever is the python equivalent of whoami and then you'd probably know.

tony power
Posts: 33
Joined: Tue Mar 08, 2016 9:07 pm

Re: PHP exec() not working as expected

Mon Jul 11, 2016 4:29 am

I think this will solve your issue

Code: Select all

sudo chmod 777 /dev/vchiq
sudo chown www-data:www-data -R /var/www

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: PHP exec() not working as expected

Mon Jul 11, 2016 4:49 am

tony power wrote:

Code: Select all

sudo chmod 777 /dev/vchiq
sudo chown www-data:www-data -R /var/www
First line, BAD. (And under most installation will be reset by udev when you reboot anyways, cause, well, it's BAD.)
Second line, under Jessie the directory is /var/www/html for the www-data group.
Account Inactive

Return to “Other programming languages”