php 如何在php上启用shell_exec和exec?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24999673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:35:38  来源:igfitidea点击:

how to enable shell_exec and exec on php?

phpapacheweb

提问by kloop

(There is some mention of this online, but none of the solutions worked.) I want to be able to use shell_exec and exec from a PHP script.

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

Meaning, use:

意思是,使用:

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

or

或者

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

According to a link I found online (http://forums.cpanel.net/f5/enable-shell_exec-one-user-109601.html), one way to do it is to add under VirtualHost the directives:

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

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

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

but when I looked at the configuration file, trying to restart the webserver, I get:

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

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)

and the server is not restarted.

并且服务器没有重新启动。

Any ideas how to enable exec and shell_exec? I can't trace the origin of this error.

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

EDIT: I am not the root on the machine. I couldn't find an php.ini file, but there is an /etc/httpd/conf.d/php.conf file and it has no disable_functions.

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

Here it is:

这里是:

#
# 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

回答by Adam

If you are not the root on the machine, and exec()function is disabled, then you can't enable it by yourself.

如果您不是机器上的root,并且exec()功能被禁用,那么您不能自己启用它。

See http://php.net/manual/en/ini.core.php#ini.disable-functions

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

disable_functions string

This directive allows you to disable certain functions for security reasons. It takes on a comma-delimited list of function names. disable_functions is not affected by Safe Mode.

Only internal functions can be disabled using this directive. User-defined functions are unaffected.

This directive must be set in php.iniFor example, you cannot set this in httpd.conf.

disable_functions 字符串

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

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

该指令必须在 php.ini 中设置,例如,您不能在 httpd.conf 中设置。

回答by Avinash Babu

You need to disable safe mode in PHP by navigating through \Apache2\bin(not folder) and restart the server.

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

Check hereand here.

检查这里这里

回答by Saurabh Chandra Patel

remove from function from

从功能中删除

disable_functions="" 

in your php.ini file

在你的 php.ini 文件中

or if you have Suhosin then check your setting in Suhosin config file under suhosin.executor.func.blacklist

或者如果你有 Suhosin 然后检查你在 Suhosin 配置文件中的设置 suhosin.executor.func.blacklist

回答by Peter Darmis

Since php_admin_value takes two arguements and doesn't need =sign, use

由于 php_admin_value 需要两个参数并且不需要=符号,所以使用

php_admin_value suhosin.executor.func.blacklist "shell_exec"

OR for blocking multiple php functions use

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

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