2016-06-14 2 views
2

[Symfonyのファイルシステム] [1]を使用しているときにファイルをsudoとしてどのようにタッチできますか?sudoとしてファイルをタッチ

は、これまでのところ私が持っている:

$fs = new Filesystem(); 
$confFile = sprintf('/etc/apache2/sites-available/%s.conf', $input->getArgument('name')); 
$fs->touch($confFile); 

しかし、このコードは、エラーで失敗します。Permission denied

[1]: http://symfony.com/doc/current/components/filesystem/introduction.html

答えて

0

あなたはsymfonyのファイルシステムコンポーネントからのapacheユーザー

HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` 

sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" /etc/apache2/sites-available/ 
1

への書き込みアクセスを追加する/etc/apache2/sites-available/上の権限を変更する必要があります。

public function touch($files, $time = null, $atime = null) 
{ 
    foreach ($this->toIterator($files) as $file) { 
     $touch = $time ? @touch($file, $time, $atime) : @touch($file); 
     if (true !== $touch) { 
      throw new IOException(sprintf('Failed to touch "%s".', $file), 0, null, $file); 
     } 
    } 
} 

あなたがそこに見るように、touch()方法PHPのbuildin touch()関数の周りの単なるラッパーです。 sudoを使用して昇格した権利でタッチする必要がある場合は、直接電話する必要があります。

shell_exec('sudo touch ' . escapeshellarg($file)); 
関連する問題