Answers.Body: <p>The problem seems to be tied to Composer not having the correct permissions. Will work with our IT team to update so Composer can write appropriately when initiated from Craft. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-26T16:12:06.910Z
Answers.LastActivityDate: 2018-06-26T16:12:06.910Z
Answers.UserDisplayName: dpayne
Body: <p>Curious if anyone has ever run into this before or may know what's going on here. I'm using the execWidget plugin (<a href="https://github.com/marionnewlevant/craft-exec_widget" rel="nofollow noreferrer">https://github.com/marionnewlevant/craft-exec_widget</a>) to run a script from Craft's dashboard that does a composer install when the lock file has changed. </p>
  
  <p>Here is the configuration for the plugin: </p>
  
  <pre><code>&lt;?php
  return [
    '*' =&gt; [
    ],
    'local' =&gt; [
      'commands' =&gt; [
        'composer install' =&gt; '../scripts/ed-day_composer.sh',
        'pull assets from production' =&gt; '../scripts/pull_assets.sh',
      ]
    ],
    'staging' =&gt; [
      'commands' =&gt; [
        'composer install' =&gt; '../scripts/ed-day_composer.sh',
        'push everything production' =&gt; '../scripts/push_all.sh',
      ]
    ],
  ];
  </code></pre>
  
  <p>Here is the composer install script:</p>
  
  <pre><code>#!/bin/bash
  
  # Get the directory of the currently executing script
  DIR="$(dirname "${BASH_SOURCE[0]}")"
  
  # Include files
  INCLUDE_FILES=(
              "common/defaults.sh"
              ".env.sh"
              "common/common_env.sh"
              "common/common_db.sh"
              )
  for INCLUDE_FILE in "${INCLUDE_FILES[@]}"
  do
      if [ -f "${DIR}/${INCLUDE_FILE}" ]
      then
          source "${DIR}/${INCLUDE_FILE}"
      else
          echo "File ${DIR}/${INCLUDE_FILE} is missing, aborting."
          exit 1
      fi
  done
  
  (cd "${LOCAL_ROOT_PATH}/craft"; HOME=${LOCAL_HOME} composer install)
  </code></pre>
  
  <p>I get a returned 127 error from the queue.log and the scrip does not actually work:</p>
  
  <pre><code>2018-06-25 14:10:12 [50.200.203.190][1][-][info][craft\queue\QueueLogBehavior::beforeExec]  [45] ExecWidget Task (attempt: 1) - Started
  2018-06-25 14:10:12 [50.200.203.190][1][-][info][marionnewlevant\execwidget\jobs\ExecWidgetTask::log] executing ../scripts/ed-day_composer.sh
  2018-06-25 14:10:12 [50.200.203.190][1][-][info][marionnewlevant\execwidget\jobs\ExecWidgetTask::log] returned 127
  </code></pre>
  
  <p>Based on testing I've done, I'm almost certain the issue is with composer because I get a success error message when I remove just the composer part of the line.</p>
  
  <p>Composer works when SSHing in. Any idea what might be causing the issue?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-25T22:31:20.757Z
Comments.Text: If you SSH in and execute `scripts/ed-day_composer.sh` directly, do you get the same error response?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-26T15:02:59.200Z
Comments.Text: Hey @BradBell - good suggestion! So if I SSH in and execute the script, it works, but still gives the same error when attempting to run it via the Craft control panel. Any idea as to what that means or where to investigate further?
Comments.UserDisplayName: dpayne
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-26T15:31:06.657Z
Comments.Text: Update here - seems likely this is tied to some sort of permissions issue as I get this error when I attempt to install a plugin from the plugin store: Error: file_put_contents(/home/ediscoveryday/www/stage/craft/composer.json): failed to open stream: Permission denied. Working to find the exact permissions I need to adjust.
Comments.UserDisplayName: dpayne
Tags: <plugins><php><composer>
Title: Composer Issue When Doing exec From a Plugin
ThreadText: # Composer Issue When Doing exec From a Plugin
  
  (Asked by: username_0 on 2018-06-25)
  
  Curious if anyone has ever run into this before or may know what's going on here. I'm using the execWidget plugin (<https://github.com/marionnewlevant/craft-exec_widget>) to run a script from Craft's dashboard that does a composer install when the lock file has changed.
  
  Here is the configuration for the plugin:
  
  ```
  <?php
  return [
    '*' => [
    ],
    'local' => [
      'commands' => [
        'composer install' => '../scripts/ed-day_composer.sh',
        'pull assets from production' => '../scripts/pull_assets.sh',
      ]
    ],
    'staging' => [
      'commands' => [
        'composer install' => '../scripts/ed-day_composer.sh',
        'push everything production' => '../scripts/push_all.sh',
      ]
    ],
  ];
  
  ```
  
  Here is the composer install script:
  
  ```
  #!/bin/bash
  
  # Get the directory of the currently executing script
  DIR="$(dirname "${BASH_SOURCE[0]}")"
  
  # Include files
  INCLUDE_FILES=(
              "common/defaults.sh"
              ".env.sh"
              "common/common_env.sh"
              "common/common_db.sh"
              )
  for INCLUDE_FILE in "${INCLUDE_FILES[@]}"
  do
      if [ -f "${DIR}/${INCLUDE_FILE}" ]
      then
          source "${DIR}/${INCLUDE_FILE}"
      else
          echo "File ${DIR}/${INCLUDE_FILE} is missing, aborting."
          exit 1
      fi
  done
  
  (cd "${LOCAL_ROOT_PATH}/craft"; HOME=${LOCAL_HOME} composer install)
  
  ```
  
  I get a returned 127 error from the queue.log and the scrip does not actually work:
  
  ```
  2018-06-25 14:10:12 [50.200.203.190][1][-][info][craft\queue\QueueLogBehavior::beforeExec]  [45] ExecWidget Task (attempt: 1) - Started
  2018-06-25 14:10:12 [50.200.203.190][1][-][info][marionnewlevant\execwidget\jobs\ExecWidgetTask::log] executing ../scripts/ed-day_composer.sh
  2018-06-25 14:10:12 [50.200.203.190][1][-][info][marionnewlevant\execwidget\jobs\ExecWidgetTask::log] returned 127
  
  ```
  
  Based on testing I've done, I'm almost certain the issue is with composer because I get a success error message when I remove just the composer part of the line.
  
  Composer works when SSHing in. Any idea what might be causing the issue?
  
  **Tags:** plugins, php, composer
  
  > **Comments:**
  > **username_1**: If you SSH in and execute `scripts/ed-day_composer.sh` directly, do you get the same error response?  
  > **username_0**: Hey @username_1 - good suggestion! So if I SSH in and execute the script, it works, but still gives the same error when attempting to run it via the Craft control panel. Any idea as to what that means or where to investigate further?  
  > **username_0**: Update here - seems likely this is tied to some sort of permissions issue as I get this error when I attempt to install a plugin from the plugin store: Error: file_put_contents(/home/ediscoveryday/www/stage/craft/composer.json): failed to open stream: Permission denied. Working to find the exact permissions I need to adjust.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-06-26. Score: 1 | Accepted answer
  
  The problem seems to be tied to Composer not having the correct permissions. Will work with our IT team to update so Composer can write appropriately when initiated from Craft.
  
  
  ---
  
  