在PHP中使用exec命令时可能出现权限问题 [英] Possible permissions issue when using exec commands in PHP

查看:268
本文介绍了在PHP中使用exec命令时可能出现权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个小型的办公室Intranet,它内置了PHP(在apache服务器上,也就是WAMP上),它使我们能够在文件服务器上创建项目文件夹.通过使用shell exec xcopy命令和以下开关/e /k /i /c将一组模板文件夹复制到新位置,可以实现此目的.

We have a small office intranet, built in PHP (on an apache server - so WAMP), that allows us to create project folders on our file server. This works by copying a set of template folders to a new location using the shell exec xcopy command and the following switches /e /k /i /c.

我们(相当)最近升级到了运行Windows Server 2008 R2 Standard的新文件服务器.现在,xcopy命令在PHP中不再起作用.但是,我知道xcopy命令是正确的,因为如果我将其复制并粘贴到命令提示符(在同一台计算机上),它将起作用.

We (fairly) recently upgraded to a new file server running Windows Server 2008 R2 Standard. Now the xcopy command no longer works from within PHP. However, I know that the xcopy command is correct because it works if I copy and paste it into a command prompt (on the same machine).

我看不到任何错误消息,但我认为这是与PHP用户"相关的某种权限问题,但我不知道到底是什么或如何解决.

I can see no error message but I assume this is some kind of permissions issue related to the PHP 'user', but I don't know exactly what or how to solve it.

apache服务器和文件服务器是两台单独的计算机.如果相关,则apache服务器是32位计算机,文件服务器是64位计算机,但是,正如我所说,我可以从32位计算机的CLI调用xcopy命令,而不会出现问题.

The apache server and the file server are two separate machines. If it's relevant, the apache server is a 32bit machine and the file server is a 64bit machine but, as I say, I can invoke the xcopy command from the CLI of the 32bit machine without a problem.

Apache进程的用户名为SYSTEM(尽管我似乎无法使用'whoami'命令进行检查)

The Apache process user name is SYSTEM (although I can't seem to use the 'whoami' command to check this)

任何指针将不胜感激.

FWIW,exec字符串如下所示……

FWIW, the exec string looks like this...

echo "xcopy \"\\\\path\\to\\folder\\xxxx_Project\\*.*\" \"\\\\path\\to\\folder\\9876_NEWPROJECT\" /e /k /i /c";

(我认为)是这样实现的...

which (I think) materializes as this...

xcopy "\\path\to\folder\xxxx_Project\*.*" "\\path\to\folder\9876_NEWPROJECT" /e /k /i /c

很明显,'9876_NEWPROJECT位确实是一个变量.

Obviously, the '9876_NEWPROJECT bit is really a variable.

推荐答案

确定.我似乎已经开始运作了.这就是我所做的-告诉我这是否是个坏主意,尽管我应该指出这是一个Intranet,所以我不太担心安全性...

OK. I seem to have got it working. Here's what I did - tell me if it's a bad idea although I should point out that this is an intranet so I'm a little less concerned about security...

  1. 转到控制面板->管理工具_>服务

  1. Go to Control Panel->Administrative Tools_>Services

选择Apache服务并点击属性"

Select the Apache service and hit Properties

在登录"选项卡上,单击此帐户:"而不是本地系统帐户",然后找到通常登录到该终端的Windows用户的用户帐户

On the Log On tab, click 'This account:' instead of 'Local System account', and then find the User account of Windows user who's normally logged on to that terminal

重新启动Apache

Restart Apache

我还修改了httpd.conf文件中的用户信息,但实际上我不确定这是否必要.

I also amended the user info in the httpd.conf file, but I'm not actually certain that that was necessary.

如果有更好的解决方案,可以用两个或两个以下音节的单词来解释,那我真听不懂!

If there's a better solution, that can be explained in words of two syllables or less, I'm all ears!

这篇关于在PHP中使用exec命令时可能出现权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆