如何在php上启用shell_exec和exec?

时间:2014-07-28 16:21:46

标签: php apache web

(在网上有一些提及,但没有一个解决方案有效。) 我希望能够从PHP脚本中使用shell_exec和exec。

含义,使用:

<? exec("echo hello world"); ?> 

<? shell_exec("echo hello world"); ?>

根据我在网上找到的链接(http://forums.cpanel.net/f5/enable-shell_exec-one-user-109601.html),一种方法是在VirtualHost下添加指令:

php_admin_value suhosin.executor.func.blacklist =“shell_exec”

但是当我查看配置文件时,尝试重新启动网络服务器,我得到:

28/07/14 17:18:26:    Syntax error on line 1 of /etc/httpd/conf.d/serv1.conf:
28/07/14 17:18:26:    php_admin_value takes two arguments, PHP Value Modifier (Admin)

并且服务器未重新启动。

任何想法如何启用exec和shell_exec?我无法追查此错误的来源。

编辑:我不是机器上的根。我找不到php.ini文件,但是有一个/etc/httpd/conf.d/php.conf文件,它没有disable_functions。

这是:

#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>

#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps

4 个答案:

答案 0 :(得分:9)

如果您不是计算机上的root用户,并且exec()功能已停用,则您无法自行启用它。

请参阅http://php.net/manual/en/ini.core.php#ini.disable-functions

  

disable_functions string

     

此指令允许您出于安全原因禁用某些功能。它采用以逗号分隔的函数名列表。 disable_functions不受安全模式的影响。

     

使用此指令只能禁用内部函数。用户定义的函数不受影响。

     

此指令必须在php.ini中设置例如,你不能在httpd.conf中设置它。

答案 1 :(得分:1)

您需要通过导航\Apache2\bin(而不是文件夹)来禁用PHP中的安全模式,然后重新启动服务器。

检查herehere

答案 2 :(得分:0)

中删除功能
disable_functions="" 

在你的php.ini文件中

或者如果您有Suhosin,请检查suhosin.executor.func.blacklist下的Suhosin配置文件中的设置

答案 3 :(得分:0)

由于php_admin_value需要两个参数并且不需要=符号,因此请使用

php_admin_value suhosin.executor.func.blacklist "shell_exec"

OR用于阻止多个php函数使用

php_admin_value suhosin.executor.func.blacklist "shell_exec, opendir, file_get_contents, phpinfo"