My dev machine과 내 서버에는 설치된 다른 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"));
}
을 만들어 서버에 나는이
을 얻을 특정 파이썬 실행 파일의 올바른 경로를 얻으려면$> 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 스크립트에서 실행 경로를 어떻게 찾을 수 있습니까?
사용자 경로가 서로 다릅니다. 테스트되지 않은 추측 : which
을 사용하고 내 서버 계정의 전체 경로 변수를 가져 와서 which
앞에로드하십시오.