Run shell command in PHP without using shell_exec - php

My server currently disabled shell_exec for security reason so I cannot run the below command inside my php script. ( which I normally can when using ssh )
echo shell_exec('youtube-dl -f 134 http://youtu.be/8R_e09bOELs');
Are there any workarounds in PHP so I can still run the above command without calling shell_exec i suppose?
Any ideas are greatly appreciated. TIA

If it's disabled - you can't. There are many other ways to download a video from YouTube. Just google: php youtube download.

Related

Why does wget on the command line work, but file_get_contents does not?

I am trying to download the contents of an html file to my Ubuntu Linux 16.04 computer using php's get_file_contents() function. However, when I do this, I get this Warning: "failed to open stream: the , aborting"
Yet when I use wget on the terminal command line, it quickly downloads the file contents.
So why does file_get_contents not work for this? Here is my php code, which produces the Warning:
$testDownload = file_get_contents("https://ebird.org/region/US-AL-001?yr=all");
echo $testDownload;
On my Ubuntu terminal command line, here is my bash code, which works quickly and flawlessly:
wget https://ebird.org/region/US-AL-001?yr=all
I want to use php because I want to automate the downloading of a number of files and need a fair bit of code to do it, and I feel much more comfortable using php than bash.
P.S. I tried various "context" solutions for the file_get_contents function that were suggested on Stack Overflow, but they did not solve the problem.
P.P.S. I earlier tried cURL and got the same redirects Warning, though I admit to not knowing much about cURL.
I found a solution: the shell_exec() function in php allows me to use bash's wget command line function within my php script. I tried it and it worked. (I will have to change the ownership of the downloaded files to get access to them.) Here is the code that worked:
$output = shell_exec('wget https://ebird.org/region/US-AL-005?yr=all');
I still don't understand why wget can get the file contents but file_get_contents cannot. But with shell_exec() I have found a php solution to complete my task, so I am happy.

how to execute a source command from php in a server

I am unable to execute a source command in linux using php.All other commands are working except this one. I need to execute the following command.
source /root/Envs/ate/bin/activate
This activates the ate-Automatic Test Equipment.Once I activate it then I need to run a python script as the script accesses the remote server.
I am able to manually run it but I am creating a tool which will automatically do it.
<?php
exec("source /root/Envs/ate/bin/activate", $output, $return);
echo "Command returned $return, and output:\n";
echo exec("python box_upgrade-pradeepa.py");
?>
The above commands returns 1 which means there is an error.But I am not sure how to run the 'source command'. The python script will run only if the source command is successful.(the python command is correct as I replaced hello.py and it ran fine.)
Could you pls help me as I am really stuck for a week?
Thanks a lot..
I found out the error. Since I am doing it using php (for a web tool) the user is Apache. 'Apache' user is unable to access the script in root folder. Moving it to another directory, I am able to run the script fine.
Thanks all..

Lame encoder command in php shell_exec doesn't work via http server

I have a problem with running lame encoder via shell_exec script in php.
And the broke my problem to just this script and noticed that the script works if I run it via php command in terminal, but doesn't work if I open it in a browser.
I have permissios of all files set to 777 just in case.
here's the code
< ?php
exec('lame -f -V 9 ../furniture/sound/107887.wav ../furniture/sound/107887.ogg');
The thing is that script works if I run it in terminal with php command, but doesn't via browser.
Oh and this scirpt takes really max two seconds, so it coundn't be a timeout or anything. I also get no php or nginx errors.
How can I solve this?
Is lame on php's execution PATH? Try replacing lame with /usr/bin/lame or whatever.
How about the relative pathnames to the file arguments? Is ../furniture/ etc. correct from the current directory as seen by PHP? If in doubt, replace these with full pathnames too and see if that fixes the problem.
Less likely but worth mentioning: You might want to check that lame itself has all its executable bits set. If you own the file and it's only executable by the owner, apache won't be able to run it.
There may be many reasons why it is not working from the webserver, perhaps resource or permission related. You can find this out by using the second optional parameter of exec:
<?php
$output = "";
exec('lame -f -V 9 ../furniture/sound/107887.wav ../furniture/sound/107887.ogg',$output);
echo $output;
?>

Run shell commands with PHP?

Occasionally my media server goes down and I'm wondering if it's possible to start it remotely using php to check the port and if it's not running invoke cron (or some other way) to run a shell command. Is this possible because this is not a strong area for me. Here's the process I use with PuTTy.
login to shell
cd to source/red5/dist
screen
./red5.sh
CTRL-A then D to detach
logout
Simplest thing is to write a shell script. And then login to remote console via PHP.
shell_exec: execute a shell command and returns the output as string.
exec: just executes an external program
A simple way to achieve what you want is to run this in screen:
while /bin/true ; do ./red5.sh ; done
If you can write a shell script that does what you need, then PHP's has exec(), system() and passthru() for you.
PHP actually has a special operator for executing shell commands, the backtick:
`cd source/red5/dist`
will go to the specified directory. (But I don't know much about shell, so I can't implement you the whole thing.)
If you need much control over the execution (I don't know whether you need here) use proc_open.
you can use corn job on php and put all command on .sh file and run like this
59 11 * * 1,2,3,4,5 root command file.sh?token
something like this ,it will be save
There is more than one good answer here, but you should opt for executing the init script for red5 instead of the .sh or .bat. There are pre-made init scripts here: http://code.google.com/p/bigbluebutton/downloads/detail?name=red5&can=2&q= and here: http://www.videowhisper.com/forum.php?ftid=48&t=init-file-red5-linux-installations-red5-linux-init.d-chkconfig

how to invoke terminal.app from a php script?

I want to invoke terminal.app from a php script is this possible if not then how do we invoke terminal using applescript/shell script. I want to use php because there is no other option for me. also after invoking terminal i want to navigate to a folder and run xcodebuild command from there. Does someone knows about it?
You could use the shell_exec command. But I fail to see how opening the terminal helps you.

Categories