无法通过 PHP 的 exec 运行 subversion [英] Trouble running subversion through PHP's exec
问题描述
我可以从命令行运行 svn 命令,但不能从 PHP 脚本中运行.重要的是,我可以在我的 Mac 上运行 PHP 脚本,它返回预期的数据就好了,但是当我将它上传到我的 Linux 服务器时,它不起作用(从 PHP 内部......我可以从终端运行 svn 命令).我很确定这是某种用户或权限问题.
I can run an svn command from the command line but not from within a PHP script. Significantly, I can run the PHP script on my Mac and it returns the expected data just fine but when I upload it to my Linux server it won't work (from within PHP... I can run the svn command from the terminal). I'm pretty sure this is a user or permission issue of some sort.
我可以运行(从命令行):
I can run (from command line):
svn log http://whatever.com/svn/foo
但没有以下工作(单独运行...不是像这样一起运行):
but none of the following work (run separately... not all together like this):
exec('svn log http://whatever.com/svn/foo');
exec('svn log http://whatever.com/svn/foo',$out);
exec('/usr/bin/svn log http://whatever.com/svn/foo');
但是这是有效的:
exec('ls');
我认为问题在于,当我从命令行运行时,我以 root 身份运行,而当我从 PHP 运行时,我以 apache 用户(www-data)身份运行?也许?关于如何能够运行 exec('svn log http://whatever.com/svn/的任何建议foo');
?
I assume the problem is that when I run from the command line I am running as root whereas when I run from PHP I am running as the apache user (www-data)? Perhaps? Any suggestions on how to be able to run exec('svn log http://whatever.com/svn/foo');
?
将权限更改为 777(只是试图让它工作!)没有帮助.
Changing permissions to 777 (just trying to get it working!) does not help.
推荐答案
以下是我认为可能有帮助的几个主题:
Here are a couple of threads that I think might help:
线程 1(阅读更多):
$cmd = '/usr/bin/svn list --config-dir /some/place file:///var/subversion/devfoundry/ 2>&1';
exec($cmd, $output);
$output = implode("\n", $output) . "\n";
echo $output;
线程 2:
Subversion 错误svn: Can't重新编码字符串"可能是由区域设置错误.试试
The Subversion error "svn: Can't recode string" can be caused by the locale being wrong. Try
<?php
putenv('LANG=en_US.UTF-8');
?>
(或任何您喜欢的语言环境)在调用 shell_exec() 之前
(or whatever your preferred locale is) before you call shell_exec()
线程 3:PHP 交互式外壳
Thread 3: PHP Interactive Shell
这篇关于无法通过 PHP 的 exec 运行 subversion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!