i've got a site on my raspberry pi with remote launching music.
The script in .php looks like this:
<?php $message=shell_exec("cvlc /home/pi/1373_128.m3u &");
header('Location:index.html'); ?>
It is working from a command line ( php5 radioon.php )
But when I am trying to launch it from website it is not, any ideas what may be wrong? The php script itself is fine, it is working when it comes to turn on light in room etc.
Related
I just started with php and I installed my xampp and got it running. Now I wanna run my code that I have, its a simple print function but when I try running it, I see the code appear in Chrome an not the print. this is what I have in my code: <?php echo "Hello World!"; ?> and when I try to run it I get the exact same thing on chrome
You should start apache and MySQL if you are connecting to DB on XAMPP then put your script in the htdocs folder then you can run your code by going to http://localhost
Another solution is by running this command to start a php server
php -S 127.0.0.1:8000 index.php
I'm using XAMPP on Windows 10, and trying to run a simple PHP script that uses the shell_exec function to call a simple R script in the same directory. Here's the PHP index.php file:
<?php
echo shell_exec('Rscript test.R');
And here's the test.R file:
print("Hello, World!")
From the command line (i.e., Git for Windows), when I run php index.php in the folder, I get the following output:
[1] "Hello, World!"
However, when I run index.php from the web browser via XAMPP and localhost, I don't see anything on the page. At first, I thought it might be a permissions issue, so I gave Full control access to all users on the folder, but it didn't seem to change anything.
Any ideas on how to get this working from the browser? Thank you.
Found the answer to the problem I was having. Apparently, even though Rscript is part of my Windows 10 PATH variable, when I try to execute an R script via shell_exec in PHP, I have to have the whole path to the Rscript executable (I guess because the PHP script / Apache server doesn't know about the path variable).
I changed the shell_exec function call as follows, and it worked:
echo shell_exec('"C:\Program Files\R\R-4.1.0\bin\Rscript" test.R');
Here's a link to the SO post that helped me figure this out:
shell_exec does not execute from browser requests
I want to run a shell script from a php-based website on my localhost (using MAMP on Mac) but it does not work, unfortunately.
Heres's the shell script:
#!/bin/bash
open /Users/my_username/Desktop/aiSee.app
If I run it from the terminal, it works fine and opens the app. Using this code in my website, it does not work:
<?php
echo exec('script.sh');
?>
No errors or something are displayed, it just doesn't work.
The script is located at the same source as the .php file for the website.
open in bash does not do what you think it does. You need cat instead:
#!/bin/bash
cat /Users/my_username/Desktop/aiSee.app
Has your issue been solved?
If not, try echo exec('sh script.sh'); or echo exec('bash script.sh');.
This question may solve your problem: how to run a .sh file from php?
I'm playing with Raspberry Pi and anm Arduino shield in order to run a script via Apache/PHP. This script simple blink a LED. I have already tested the script via shell and it works fine, with the command
/root/arduPi/blink_test
I'm able to see my LED blinking. So I made the same thing via Apache PHP with this short PHP script
<?php
if(isset($_GET['cmd'])){
echo '/root/arduPi/'.$_GET['cmd'];
exec('/root/arduPi/'.$_GET['cmd']);
}
?>
but nothing happen and no error has been displayed.
I tested the PHP code with
<?php
phpinfo();
?>
and it's fine. How can I fix this problem?
I had the same issue a while back it was because Apache does not have permission to access certain devices on the Pi. I fixed this by getting rid of the need to be root to access these devices. HERE Is my post about this same issue the fix was to setup sudo as passwordless.
THIS is what I used to accomplish setting up sudo as passwordless. You should then be able to execute the script as follows exec('sudo /root/arduPi/'.$_GET['cmd']);
I have been trying unsuccessfully so far to write a php script that will run when a page is opened and that will launch metasploit!
I ve tried shell_exec and exec and all the other alternatives but although I can get it to do simple things (i.e. ls, cds etc) if I try msfconsole it doesnt do anything!
I have also tried a different script that launches firefox and again nothing happens!
Now i know that php runs on the server and I m not expecting to see a console or firefox opening in the clients machine! Instead in order to check if it works I am trying to echo out the output of the shell_exec!But anyway since im hosting the files on my machine (i.e. this is the server and a VM is the client) if it could actually launch firefox i should be able to see the app opening here in the same way as by just doing this from the command line!
What am I missing?
Is there any other way to do this?(i.e. Launch metasploit everytime a user opens up my page)
NOTE: I've tried specifying the full path for msfconsole but that didnt work either!
Heres what I have so far:
$output = shell_exec('/opt/local/libexec/metasploit3/msfconsole;show');
echo "<pre>$output</pre>";
The ";show" bit was used in order to actually make it run something and print some stuff but didnt make any difference!
When you run a gui application from the command prompt in a X window system, it will use the default display. When you run it using php which is embedded in apache webserver, the program may not know where to display the gui application.
there are 2 things to make this work.
The program that executes the gui application must have permission to use display
you need to tell the program which display to use.
I used the following in my php script
<?php
$cmd = `export DISPLAY=:0; gedit`;
shell_exec($cmd);
?>
and ran the script from terminal using php -f test.php
I got the gedit up and running.
You can test the same with the script in apache too.
Please add apache user with privileges to access display server
update: I just added the following in /etc/apache2/apache2.conf (I am using ubuntu)
User poomalai
Group poomalai
and restarted the web server
sudo service apache2 restart
now I accessed localhost/test.php
and Presto!! I got the gedit :)
Hope this helps