运行php脚本以在浏览器上通过Shell执行hadoop命令 [英] Running php script to execute hadoop command via shell on browser

查看:107
本文介绍了运行php脚本以在浏览器上通过Shell执行hadoop命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试通过php中的 shell_exec()在终端上执行hadoop命令,并尝试通过浏览器中的url运行该脚本.我一直面临一个主要问题:

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";
?>

它显示所需的结果,HDFS根目录上所有可用项目的列表.但是,当尝试通过url运行以下脚本时,它将显示以下结果:

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.

当我将脚本更改为:

<?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";
?>

当我使用 php myscript.php 通过终端运行它时,它会工作并在HDFS根目录中创建一个目录.但是当我尝试通过浏览器通过脚本中具有不同目录名称的URL运行它时,它只打印 BeginEnd 而不在HDFS根目录下创建目录.

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.

[已更新]

当我访问apache日志文件时,在我加载url localhost/myscript.php 之后,它说了以下一行:

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

当我尝试使用Flask通过Python执行相同的脚本时.这两个命令"mkdir"和"ls"都可以完美运行,并在浏览器中显示所需的结果.

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.

注意:当我执行python脚本进行所需的工作时,我不使用apache,而是使用Flask托管了自己的服务器.

NOTE: When I execute python script for the desired work i do not use apache, i used Flask to host its own server.

应该是什么问题?

推荐答案

查看您的Apache日志文件(error.log/access.log).用于Apache的php.ini与用于php-cli的php.ini不同.也许您有一个open_basedir限制,并且无法在此目录之外运行可执行文件.

Take a look into your apache log files (error.log / access.log). The php.ini used for apache is not the same than the php.ini used with php-cli. Maybe you have an open_basedir restriction and you cannot run executable outside this directory.

http://phpsec.org/projects/phpsecinfo/tests/open_basedir.html

您还可以通过使用内部带有phpinfo函数的test.php文件并浏览来验证这些信息:

You can also verify these informations by making a test.php file with phpinfo function inside and browse it:

<? phpinfo() ; ?>

这篇关于运行php脚本以在浏览器上通过Shell执行hadoop命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆