My devマシンと私のサーバーには、インストールされているさまざまなpythonバージョンのパスがあります。fastCGIスクリプト内で実行可能なパスを取得する
私はこの
$> php -r 'require("./class.my.php"); $path=MyClass::pythonPath("2.7"); var_dump($path); var_dump(file_exists($path));'
string(18) "/usr/bin/python2.7"
bool(true)
そして、私はこの
取得サーバー上で操作を行うことができ、私はこの方法で私のdevのマシンでstatic function pythonPath ($version='') {
$python = $version === '' ? 'python': '';
if (preg_match('/^\d(\.?\d)?$/', $version)) {
$python = 'python'.$version;
}
return trim(shell_exec("/usr/bin/which $python 2>/dev/null"));
}
作られた特定のPythonの実行可能ファイルの正しいパスを取得するには
$> php -r 'require("./class.my.php"); $path=MyClass::pythonPath("2.7"); var_dump($path); var_dump(file_exists($path));'
string(27) "/opt/python27/bin/python2.7"
bool(true)
しかし、このメソッドをfastCGIで使用すると、which
の結果は空です(CentOS 6)。 私が読んだ限り、which
はユーザーの$PATH
で検索します。これは、スクリプトを実行するユーザー(私の推測httpd
)がアカウントユーザーと同じパスを持っていないため、which python2.7
の結果が得られない理由があります。
したがって、fastCGIスクリプト内で実行可能パスを見つけるにはどうすればよいですか?
ユーザーパスが異なる。スクリプトは、「誰」ユーザーが実行している私のサーバー上で