* failed to open vchiq instance - php

I try to play sound from a php script to my raspberry pi 3 via the audio jack. I use in the php script the following code:
<?php
$fetch = 'wget "http://192.168.1.127/sound.mp3" -O sound.mp3 --no-check-certificate';
$play = 'omxplayer -o local sound.mp3';
echo shell_exec($fetch);
echo shell_exec("sudo chown upload sound.mp3");
echo shell_exec($play);
?>
I got the file from a local ip adress and save it to the pi. Then I play the sound via the omxplayer command. On the real shell (over SSH in Putty), the Pi will output the sound without any problems. When I try the script, I got the following error message when I use the omxplayer command.
* failed to open vchiq instance
I searched then in forums for this error. They mean that it will be something with the missing permission of the file. For that I set the whole directory to the permission level 777 and the fileowner, as you can see in the script, to upload.
Unfortunately, this didn't work. Does anyone have another solution to get an output from the pi?
Thanks for every responses.

Omxplayer is a video and audio player. Your user needs to be in the video group, even though you only want to playback audio.
Don't use the 777 mode on the /dev/vchiq because it's not secure! A better solution is to add your user to the system group called video. For example:
To add user testuser in your Linux system to the video group, use this command:
usermod -aG video testuser

Finally I found a solution for that problem, after I searched again. The problem was with a directory in the /dev. I hit the following command in the command line and it works great.
sudo chmod 777 /dev/vchiq

A lot of users have actually been brought to this question because they tried raspistill and it returned this error.
In any case, the error is usually because you forgot to add the sudo, so sudo raspistill -o output.jpg should work.

Related

php shell_exec($cmd) do not run in a cronjob

sorry for that (I believe) poor question, but google and other articles in this forum can't help me...
I'll run the a php script with following code in it:
$cmd="duck -u user_name -p pwd -parallel 1 -e overwrite -y --throttle 1024 --upload path to remote file absolute_path_to_local_file";
$shellResponse=shell_exec($cmd);
This works well, when I call this php file in the browser.
But it fails, when I call the script within a cronjob.
With a cronjob i get following errormessage:
sh:1: duck not found
I believe this can be a permissions problem, but I'm new in this area and do not know where I can set the permissions and what I have to do.
Can anybody please help me?!
Cron jobs do not get the normal PATH env variable that is usually available.
Try using the absolute path for the 'duck' command instead.
Example:
$cmd = "/usr/bin/duck ..."
To find the absolute path, you can type
which duck
on a normal command prompt

Starting mjpg stream from a PHP file with shell_exec

I am trying to start the mjpg process from inside a PHP file on my Raspberry Pi. This is the code I am using in the PHP file.
<?php
//this execution does not work, nor does it echo anything if i try and echo it
$cmd = 'mjpg_streamer -i "/usr/local/lib/input_uvc.so -d /dev/video0 -y -r 640x480 -f 10" -o "/usr/local/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"';
shell_exec($cmd);
?>
<img src = "http://ip:8090/?action=stream" />
The command works if I execute it directly from the shell and the stream also works in this case, but I want the process to start whenever I access the page, which is not happening right now.
What's the mistake?
The mistake is (almost certainly) due to a permission based problem.
More than likely when you execute the mjpg_streamer library from the CLI you're logged in as someone with sudoer permissions or the like, who can easily execute this.
You must realize that the user who will be making the request to execute the mjpg_streamer library will be the same user that owns the instance of Apache handling the request.
In this scenario, the easiest way to troubleshoot this would be to log into the CLI and then su www-data (likely who owns your instance of apache) and check if you can then run it. If you get a permission denied, then you'll need to change how access to that library is granted. Changing ownership of the library is probably not the best bet, but you could likely get away with modifying the group.

shell_exec not working when excuted from browser | ssh | scp | keygen

What I want to do is:
execute "shellUnlock.php" from browser
then "scriptUNLOCK.sh" executed from the "shellUnlock.php"
then "resultUNLOCK.log" created from the scriptUNLOCK.sh
then show "resultUNLOCK.log" in browser
Notes:
For the SSH i used keygen, so i don't have to insert any password again from my server.
I used the SCP to copy "resultUNLOCK.log" created in "da.serv.er" to my own folder.
I have try it from browser, but it shows no output at all.
The script works well when I execute from putty but from shell_exec it's not work.
And I don't have access to install anything in the server.
my "shellUnlock.php" file
$myfile = fopen("nameUSER.txt", "w") or die("Unable to open file!");
$txt = "USERNAME";
fwrite($myfile, $txt);
fclose($myfile);
shell_exec('./scriptUNLOCK.sh');
if (file_exists("resultUNLOCK.log"))
echo readfile("resultUNLOCK.log");
}else{
echo "Please Try";
}
my "scriptUNLOCK.sh" script
#!/bin/bash
HOST='user#da.serv.er'
HOME='/home/web/UNLOCK'
DIR='/somewhere/script/UNLOCK/'
cd ${HOME}
while read nameUSER
do
ssh ${HOST} <<END_SCRIPT
cd ${DIR}
unlock.sh ${nameUSER} > resultUNLOCK.log
exit
END_SCRIPT
cd ${HOME}
scp ${HOST}:${DIR}resultUNLOCK.log ${HOME}
done < nameUSER.txt
Now please help me. I'm totally confused. Thanks.
If the script works fine when running it from the command line but it doesn't when you trigger it via your webserver it has to be a permission or/and path problem.
Ensure that the apache user (either www-data, www or apache by default) has write access to the UNLOCK folder and I think it will work.
And you should probably change the name of your "HOME" variable since HOME is a fix environment variable in Linux. I don't know if this is a problem, but i would change the name nevertheless to avoid disorder.
Best way would be to make it via groups
sudo usermod -a -G www-data <apache_user>
sudo chgrp -R www-data /somewhere/script/UNLOCK/
sudo chmod -R g+w /somewhere/script/UNLOCK/
So at least the user you use to login via putty must have the rights to modify the accessibility of the directory. If not, you can either contact your system administrator or use another folder you have access on.
I hope this helps.
Kind Regards
My problem solved!
Instead using shell_exec in php, i directly execute the script using crontab.
I'm sure I can find other best solution to solve this case if I have no limited time.
But the time forces me. :D
Well at least IT WORKS!
Thanks all..!

shell_exec('/usr/sbin/i2cget -y 1 *') don't work

I use a raspberrypi to control an Arduino UNO board.
I try to use i2c with php to reports on a site heberger on raspberry.
Php but do not want to run shell_exec ("/usr/sbin/i2cget -y 1 0x04 0x02 b").
If I put it Inthe shell I see the right result.
And when I try with shell_exec("ls-the art"); the site displays the correct result!
where is my problem? I gave all rights to the script, but not more matches, the path to i2cget is correct.
what can I try to solve this problem?
You could read the fine manual, run the command as root, run the service that runs the command as root, configure the service do include /usr/sbin/ in its PATH, load the necessary kernel modules, assert that the given chip and data addresses make sense and post your question to an appropriate audience.
Try like below.
Marked /usr/sbin/i2cget as UID.
- or -
sudo chmod 4755 /usr/sbin/i2cget
It works!

How to run mplayer with audio speaker output from PHP web script on linux?

I am logged in to linux feora 15 distro with username: stackoverflow.
My browser execute in the local system a PHP script to play a music using PHP system("mplayer /tmp/stackoverflow.wav"), passthru("mplayer /tmp/stackoverflow.wav") command. Such as linux command.
As a user stackoverflow i dont hear any audio. But i can see that mplayer /tmp/stackoverflow.wav is running which has duration of 8minutes audio.
My question is: how can i use PHP system("mplayer /tmp/stackoverflow.wav"); to switch user and run the same command, so that i can hear my music with my PHP?
<?php
// for example
switchuser("su stackoverflow password");
system("mplayer /tmp/itworks.wav");
?>
I would like to do the same.
When I try to run mplayer just via shell_ecex(); it does not select pulseaudio for output. Even when I include into the command -ao pulse it doesn't work.
When I try to run the mplayer command with sudo (I added www-data to the sudoers file), mplayer apparently starts playing (according to ressource usage) but there is no output. When I kill the mplayer instance manually the whole sound output is blocked, even when I launch mplayer via the console.
Do you have any tips for me how to run mplayer via PHP?
Edit: I have a solution! My command looks like this:
shell_exec('sudo -u [username] nohup mplayer -slave [mplayer attributes go here] 2> /dev/null > /dev/null &'));
This also stops the php script from waiting for a result from mplayer, so it starts mplayer and continues operation.
The direct answer to your question would be to use sudo, as in
system("sudo -u <username> mplayer /tmp/itworks.wav")
But, I'm not sure this will solve your problem. Firstly, where do you want the sound outputted? The server or the client/browser? The above technique will work on the server. For the browser, you'd need to get the client to load the .wav file as an object or some such and deal with it, presumably via a plugin.
You mention that you can see a running mplayer process though? If you are at the server (or the server and client are on the same physical machine) and you can't hear any output, then there's something else going on. It's possible that the web server process user doesn't have permission to use the audio card, but then I doubt the mplayer process would continue for so long without terminating with "permission denied" error. To figure this out, we'd need more info I guess

Categories