2012-01-14 17 views
-1

私はPHPからsuとしてコマンドを実行しようとしています。 sudo: no tty present and no askpass program specifiedPHP - rootとしてコマンドを実行してください。

感謝を - 私はターミナルでコマンドを入れたりphp /var/www/script.phpと、それは完璧に動作しますが、私はブラウザを介してscript.php開いたとき、それは返し

thisによると

+0

:あなたは、単に次のコードを使用しますダウンロードした後

?エラーメッセージのどの部分がクリアされていませんか? – Jon

+0

質問は私がルートとしてコマンドを正しく実行する方法です。 – user997379

答えて

0

:リモートコマンドを実行するときに

sshはデフォルトで端末を割り当てません。 ttyがなければ、sudoはパスワードを要求するときにechoを無効にできません。 sshの "-t"オプションを使って、ttyの割り当てを強制することができます。 パスワードが 画面にエコーされても構わない場合は、「visiblepw」sudoersオプションを使用してこれを許可することができます。

0

私は最近、PHPが実際のBashシェルを取得して操作できるプロジェクトを公開しました。ここに取得:https://github.com/merlinthemagic/MTS

実際のbashシェルをrootとして取得できます。その後、PHPスクリプトを起動するか、bashで直接コマンドを実行することができます。そこで質問が何であるか

$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true); 
    $return1 = $shell->exeCmd('yourFirstCommand'); 
    $return2 = $shell->exeCmd('yourSecondCommand'); 
    //the return will be a string containing the return of the script 
    echo $return1; 
    echo $return2; 

    //or if you want to trigger your script as root 
    $return3 = $shell->exeCmd('php /my/script.php'); 
    echo $return3; 

    //If your script contains code to make an SSH connection to another server 
    //there is a much easier way to do that using the project: 
    $shell = \MTS\Factories::getDevices()->getRemoteHost('ip_address')->getShellBySsh('username', 'secretPassword'); 
関連する問題