I have been trying to execute a hadoop command on terminal via shell_exec() in php and trying to run that script through url in browser. I have been facing a major problem:
When I try to run the following script in terminal:
<?php
echo "Begin";
echo shell_exec('hadoop fs -ls /');
echo "End";
?>
It shows the desired result, the list of all items available on the root of HDFS. But when try to run the following script via url, it shows the following result:
url: localhost/myscript.php
BeginEnd
Nothing else! the script is working in terminal but not in browser.
When I change the script to :
<?php
echo "Begin";
echo shell_exec('ls /');
echo "End";
?>
It shows all the items available in the root directory of local file system both in terminal and the browser.
I tried to change the command to check whether the script is running or not.
<?php
echo "Begin";
echo shell_exec('hadoop fs -mkdir /test');
echo "End";
?>
When I run it through terminal using php myscript.php, it works and creates a directory in HDFS root directory. but when I try running it through browser via url with different directory name in the script, it just print BeginEnd without creating the directory at HDFS root.
[UPDATED]
When I access the apache log files, it says the following line after i load the url localhost/myscript.php :
[Thu Apr 07 10:04:07.187673 2016] [core:notice] [pid 1540] AH00094: Command line: '/usr/sbin/apache2'
sh: 1: hadoop: not found
When I try to execute the same script by Python using Flask. Both of the commands "mkdir" and "ls" works perfect and show the desired result in browser.
NOTE: When I execute python script for the desired work i do not use apache, i used Flask to host its own server.
What should be the problem ?