php 在 wamp 服务器中启用 shell_exec()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12757891/
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
Enable shell_exec() in wamp server
提问by Selva
Recently I have passed one issue on wamp server..I need to use the shell_exec()function in PHP for running some external shell script (some checksum file) . But in my wamp server the function is disabled by default. I searched in google but I cant find out the solution. So I try to put that code in live server. But there's also the same problem. I contacted the technical person for that server but he said we cant enable shell_script. It is security violence.
最近我在 wamp 服务器上通过了一个问题..我需要使用shell_exec()PHP 中的函数来运行一些外部 shell 脚本(一些校验和文件)。但是在我的 wamp 服务器中,该功能默认是禁用的。我在谷歌搜索,但我找不到解决方案。所以我尝试将该代码放在实时服务器中。但也有同样的问题。我联系了该服务器的技术人员,但他说我们无法启用 shell_script。这是安全暴力。
So only way is trying in wamp server... How to enableshell_exec()or exec()..?
所以唯一的方法是在 wamp 服务器中尝试......如何启用shell_exec()或exec()......?
回答by Sturmi
The following line was the best I read to this problem: "You need to disable safe mode in the php.ini located in the \Apache2\bin folder, not the php folder. Restart Apache2 service right after to load the new settings."
以下行是我读到的最好的问题:“您需要在位于 \Apache2\bin 文件夹中的 php.ini 中禁用安全模式,而不是在 php 文件夹中。加载新设置后立即重新启动 Apache2 服务。”
The solution is:
解决办法是:
stop all services from Wamp-Server and close the programm
Open .../wamp/bin/apache/Apache2../bin/php.ini
copy php.ini to desktop and open it
set safe_mode_exec_dir(line after = is empty, so IT IS ON!!!) set it off!
save
copy back to dir (maybe you need admin rights)
start wamp-server
enjoy exec() and co.
停止 Wamp-Server 的所有服务并关闭程序
打开.../wamp/bin/apache/Apache2。. /bin/php.ini
将 php.ini 复制到桌面并打开
设置safe_mode_exec_dir(= 后面的行是空的,所以它是打开的!!!)把它关掉!
节省
复制回目录(也许您需要管理员权限)
启动 wamp 服务器
享受 exec() 和 co。
回答by leplandelaville
I was having the same problem and tried a lot of solutions out there. What worked out for me was running XAMPP as Admin.
我遇到了同样的问题,并尝试了很多解决方案。对我有用的是以管理员身份运行 XAMPP。
回答by xdazz
Open your php.inifile used by wamp, find the disable_functionspart, change it and restart the server.
打开php.iniwamp 使用的文件,找到该disable_functions部分,更改它并重新启动服务器。
回答by Tiberiu-Ionu? Stan
You need to disable safe mode in the php.ini located in the \Apache2\binfolder, not the php folder.
您需要在\Apache2\bin文件夹中的 php.ini 中禁用安全模式,而不是 php 文件夹。
Restart Apache2 service right after to load the new settings.
加载新设置后立即重新启动 Apache2 服务。
回答by Ishan Bhuta
I think we can use these steps
我想我们可以使用这些步骤
- Open wamp\bin\apache\apache2.4.9\bin(doesn't matter apache version)
- Open php.ini file in editor
- Search for "disable_functions".
- Remove execand shell_execfrom disable function
- Restart all services.
- 打开wamp\bin\apache\apache2.4.9\bin(与apache版本无关)
- 在编辑器中打开 php.ini 文件
- 搜索“ disable_functions”。
- 从禁用功能中删除exec和shell_exec
- 重启所有服务。
Enjoy!!!
享受!!!
回答by coltonon
<?php
function _exec($cmd)
{
shell_exec('SCHTASKS /F /Create /TN _proc /TR "' . $cmd . '"" /SC DAILY /RU INTERACTIVE');
shell_exec('SCHTASKS /RUN /TN "_proc"');
shell_exec('SCHTASKS /DELETE /TN "_proc" /F');
}
_exec("mspaint.exe");
?>
Rather a hack, but if you're trying to start anything with a gui, or hangs, this is what I found that works.
而是一种 hack,但是如果您尝试使用 gui 启动任何东西,或者挂起,这就是我发现可行的方法。
回答by Estefano Salazar
Is not a "server problem". This configuration is not recommended. You must run the WAMP server in Administrator mode.
不是“服务器问题”。不推荐这种配置。您必须以管理员模式运行 WAMP 服务器。
Here are some information: PHP doesn't work with shell_exec(), system() or passthru()
回答by Ariaan
have you tried backticks? (in case safemode is OFF)
你试过反引号吗?(如果安全模式关闭)
`ls -hal`
Windows equivalent would be
Windows 等价物是
`dir \AH`
回答by Jens A. Koch
Try using a WAMP server stack, which is clearly for development, like WPN-XMor XAMPP. Without any security limitations for the developer. So you won't run into trouble, when executing system(), shell_exec(), passthrough().
尝试使用 WAMP 服务器堆栈,这显然是用于开发的,例如WPN-XM或XAMPP。对开发人员没有任何安全限制。因此,在执行 system()、shell_exec()、passthrough() 时,您不会遇到麻烦。
回答by Jimmy M
I just found a better explanation, but didn't tried it yet. Have a look - http://discussion.accuwebhost.com/linux-server/1096-how-enable-shell_exec-function-one-account.html
我刚刚找到了一个更好的解释,但还没有尝试过。看看 - http://discussion.accuwebhost.com/linux-server/1096-how-enable-shell_exec-function-one-account.html

