exec 和 composer 的权限被拒绝

permission denied with exec and composer

我试图执行一个函数来更新作曲家或不更新。 但是,结果显示权限被拒绝

我的 composer.json 在 777 我的 composer.lock 在 644

谢谢你

public function update() {
  $cmd =  static::$root . ' composer update 2>&1';

  exec($cmd, $output);

  return $output;
}

结果:

array(1) { [0]=> string(59) "sh: 1: /home/www/demo/shop/: Permission denied" }

我假设因为在 composer 之前有一个 space,其中 static::$root 被前置,所以您正在 static::$root 中指定路径或环境变量。这将不起作用,因为您不能依赖路径中的作曲家。您可能想使用 exec("/usr/bin/composer update", $output);/bin/bash -c /usr/bin/php /path/to/composer.phar update 或这两个命令的某种组合。