windows apache 服务 php exec 不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5769800/
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-09-15 16:42:45  来源:igfitidea点击:

apache service php exec not working

phpwindowsapacheservice

提问by waquner

I looked up all other questions regarding this, but they didn't help, so:

我查找了有关此的所有其他问题,但它们没有帮助,因此:

I'm running xampp(lite) on a Windows Server 2003 machine inside a domain, apache is installed as a service. The problem is: the PHP functions exec, system, passthru, etc. do nothing, no error messages (log level of apache is debug, php error_reporting is E_ALL), no program execution, nothing, it acts as if the function call wasn't there

我在域内的 Windows Server 2003 机器上运行 xampp(lite),apache 作为服务安装。问题是:php函数exec、system、passthru等什么都不做,没有错误信息(apache的日志级别是debug,php error_reporting是E_ALL),没有程序执行,什么都没有,就好像函数调用不是'在那里

I tried different approaches: exec, system, ..; proc_openand the WScript.Shell COMobject, nothing worked. I tried using the absolute path, gave permissions to the user, tried tons of different .exe's doing different stuff, nothing worked, nothing every was executed.

我尝试了不同的方法:exec、system、..;proc_openWScript.Shell COM对象,没有任何效果。我尝试使用绝对路径,向用户授予权限,尝试了大量不同的 .exe 做不同的事情,但没有任何效果,也没有执行任何操作。

I gave the Apache service my username; gave it its own apache user; gave it the system user and ticked "Allow interaction with desktop".

我给了 Apache 服务我的用户名;给它自己的 apache 用户;给它系统用户并勾选“允许与桌面交互”。

php safe_mode is off, also no functions are disabled.

php safe_mode 关闭,也没有禁用任何功能。

When running apache NOT as as service, everything works perfectly.

当 apache 不作为服务运行时,一切正常。

Any idea what could be wrong?

知道有什么问题吗?

TIA

TIA

回答by blackfilms

If you try to launch GUI apps from a service in Vista, you'll have lots of trouble. As a security feature, Vista mediates the interaction of services with the desktop using 'Interactive Services Detection'.

如果您尝试从 Vista 中的服务启动 GUI 应用程序,则会遇到很多麻烦。作为一项安全功能,Vista 使用“交互式服务检测”调解服务与桌面的交互。

That means, if you are running PHP as a module of an Apache service, you won't be able to launch GUI apps using any method. This kind of thing just won't work:

这意味着,如果您将 PHP 作为 Apache 服务的模块运行,您将无法使用任何方法启动 GUI 应用程序。这种事情是行不通的:

$WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run("notepad.exe", 7, false);

$WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run("notepad.exe", 7, false);

So, if you want to use Apache/PHP as a proxy for launching GUI apps, you'll need to run Apache as a console application.

因此,如果您想使用 Apache/PHP 作为启动 GUI 应用程序的代理,您需要将 Apache 作为控制台应用程序运行。

First, if Apache is already installed as a service, you'll need to set it's startup type to "manual" using the services snap-in. (%SystemRoot%\system32\services.msc) Search for Services in the start menu search box.

首先,如果 Apache 已作为服务安装,则需要使用服务管理单元将其启动类型设置为“手动”。(%SystemRoot%\system32\services.msc) 在开始菜单搜索框中搜索服务。

Then add a shortcut to C:\apache\bin\httpd.exe (or wherever Apache is installed) to your Startup folder, and set that shortcut to start minimized. You can use an app like TrayIt! to force Apache down into the system tray.

然后将 C:\apache\bin\httpd.exe(或安装 Apache 的任何地方)的快捷方式添加到您的启动文件夹,并将该快捷方式设置为最小化启动。您可以使用像 TrayIt 这样的应用程序!强制 Apache 进入系统托盘。

Then use any of the methods outlined on the PHP website and you will be able to open a Windows application from PHP and see it's GUI.

然后使用 PHP 网站上概述的任何方法,您将能够从 PHP 打开 Windows 应用程序并查看它的 GUI。

回答by Richard Dickinson

Check your PHP.ini file just incase those functions you've mentioned are in the disallowed setting. Not something standard from a XAMPP release though, but worth checking.

检查您的 PHP.ini 文件,以防万一您提到的那些功能在不允许的设置中。虽然不是 XAMPP 版本的标准,但值得检查。

You say you're not getting any errors, I will assume your server is set as a service, therfore any commands sent using exe, system, passthru etc.. will be done in the background, so you won't see them running, but you should be able to capture data though.

你说你没有收到任何错误,我假设你的服务器被设置为服务,因此使用 exe、system、passthru 等发送的任何命令都将在后台完成,所以你不会看到它们在运行,但是您应该能够捕获数据。

<?php

//Start an object to capture data.
ob_start();

//Check we have access to the command line.
exec("ping google.com -n 1");

//Capture the output.
$output = ob_get_clean();

//Let's display it.
echo $output;

?>

Try the above and see what happens, you should get a response from command line, otherwise, it's possible it could be due to permissions.

试试上面的方法,看看会发生什么,你应该从命令行得到响应,否则,可能是权限问题。