Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

apache - how to enable shell_exec and exec on php?

(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.

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:

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.

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.

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

See 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.ini For example, you cannot set this in httpd.conf.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...