title: Grunt command in Bash script skipped when called from php page (MAMP hosted)
body: <p><strong>Background</strong></p>
  <p>So I am creating a HTML and PHP page that when the user clicks a button uses tools such as Ionic to build an app from config files and sign it and eventually upload it automatically to the relevant store.</p>
  <p>I have created the PHP index page, which lives in the &quot;htdocs&quot; folder of a MAMP server and works beautifully when you navigate to &quot;localhost:8888&quot; in a browser, that all works fine and when the &quot;submit&quot; button is clicked a quick AJAX call is made that runs a another PHP file that begins the bash scripts that do all the work of arranging files and folders, unzipping and eventually using grunt to run a variety of ionic processes on the files.</p>
  <p>The problem arises with the &quot;grunt&quot; command. I have the script going through every command perfectly and I even have a log file so I can check its progress when the script is called by using the page's button. It goes all the way until the grunt command, then it simply seems to skip it. When I run the script using all the same parameters in the terminal it works beautifully and even the grunt call is hit and carried out nicely, but as soon as I try and use the exact same script by using the created front end page, the grunt command is ignored and every other command seems to be successfully hit.</p>
  <p>Just to re-iterate when I run the script using the terminal and pass in the exact same input parameters, it works, but when I use the page and click the button, everything else works and the grunt command is skipped or missed or fails?</p>
  <p><strong>Question</strong></p>
  <p>So my question is why is this happening and how can I fix it? Is it something to do with MAMP or grunt?</p>
  <p><strong>More Information:</strong></p>
  <p>The PHP page is stored in the htdocs folder of MAMP so that when you enter localhost into the browser it loads that index page.</p>
  <p><em>/Applications/MAMP/htdocs</em></p>
  <p>The PHP file that calls the scripts is also stored here and returns to the index page a success parameter as it is called using a quick AJAX function.</p>
  <p>The scripts however are located locally on the machine just in a simple test folder I created to test the system. Perhaps this is where the problem is arising? However as stated the script works, and moves folders, copies them, unzips them, but as soon as the grunt called is made to run a few ionic processes it skips it.</p>
  <p><em>Thank you for taking the time to read this and if you have any questions or require code please let me know, however I believe it not to be a code based issue more of a theoretical issue. But I am more than willing to post the code if necessary.</em></p>
  <p><strong>Added code snippet</strong>
  I have added the code that seems to be causing the trouble, this is from the script that is called. This snippet exists within an IF statement and manages to get all the way successfully down to the &quot;exec grunt&quot; call, I have tried many different variations of this including cd-ing into the directory then just commanding &quot;grunt&quot; and even putting the grunt command into its own php script to see if that works, nothing works with this grunt command.</p>
  <pre><code>echo &quot;=====================================&quot;
  echo &quot;|                                   |&quot;
  echo &quot;| Sources avaliable, ok to proceed  |&quot;
  echo &quot;|                                   |&quot;
  echo &quot;=====================================&quot;
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Sources file is avaliable &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  echo &quot;=====================================&quot;
  echo &quot;|                                   |&quot;
  echo &quot;|   Beginning the UN-zip and Move!  |&quot;
  echo &quot;|                                   |&quot;
  echo &quot;=====================================&quot;
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Un-zipping now starting &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  if [ -d &quot;zz_app-framework_adrian_plus&quot; ]; then
      echo &quot;Framework already exists so skip the un-zip phase&quot;
  else
      echo &quot;Framework not present so, unzipping into current dir&quot;
      unzip ../../Master/zz_app-framework_adrian_plus.zip -d .
  fi
  #REVISED --- #unzip ../../Master/zz_app-framework_adrian_plus.zip -d .
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Un-zipping done! &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  echo &quot;=====================================&quot;
  echo &quot;|                                   |&quot;
  echo &quot;|          Unzip complete           |&quot;
  echo &quot;|                                   |&quot;
  echo &quot;=====================================&quot;
  
  #REVISED --- #cd zz_app-framework_adrian_plus
  
  rm -r zz_app-framework_adrian_plus/sources
  unzip -o sources.zip -d zz_app-framework_adrian_plus/
  
  rm -r zz_app-framework_adrian_plus/sources/appsmart-cfg.json
  
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Config now swithcing &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  pwd
  
  locate=$(pwd)
  
  php ../../Master/getConfig.php &quot;$apptoken&quot; &quot;$locate&quot;
  
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Config file replaced! &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  echo &quot;=====================================&quot;
  echo &quot;|                                   |&quot;
  echo &quot;|  Sources and Config updated...    |&quot;
  echo &quot;|                                   |&quot;
  echo &quot;=====================================&quot;
  
  echo &quot;=====================================&quot;
  echo &quot;|                                   |&quot;
  echo &quot;|     Beginning Ionic Build         |&quot;
  echo &quot;|                                   |&quot;
  echo &quot;=====================================&quot;
  
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Beginning Ionic processes &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  if [ -d &quot;zz_app-framework_adrian_plus/project/platforms&quot; ]; then
      echo &quot;Platforms already exist, deleting first before continuing!&quot;  &gt;&gt; &quot;$LOG_FILE&quot;
      rm -r zz_app-framework_adrian_plus/project/platforms
  else
      echo &quot;No Platforms exists, please check folders, however script will continue&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  fi
  
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== About to call grunt &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  exec grunt --base zz_app-framework_adrian_plus/project/ --gruntfile zz_app-framework_adrian_plus/project/Gruntfile.js
  
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Grunt completed! &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  echo &quot;=====================================&quot;
  echo &quot;|                                   |&quot;
  echo &quot;|    Build Complete, Now Signing    |&quot;
  echo &quot;|                                   |&quot;
  echo &quot;=====================================&quot;
  
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Beginning Signing process &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  locationOfApk=$(pwd)
  fulllocation=&quot;$locationOfApk/zz_app-framework_adrian_plus&quot;
  keylocation=&quot;../../Master/&quot;
  
  ../../Master/./signit.sh &quot;$apptoken&quot; &quot;$ident&quot; &quot;$slug&quot; &quot;$fulllocation&quot; &quot;$keylocation&quot;
  
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Signing Done! &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  
  
  echo &quot;=====================================&quot;
  echo &quot;|                                   |&quot;
  echo &quot;|         Signing Complete!         |&quot;
  echo &quot;|                                   |&quot;
  echo &quot;=====================================&quot;
  
  echo &quot;=====================================&quot;
  echo &quot;|                                   |&quot;
  echo &quot;|       Uploading to store...       |&quot;
  echo &quot;|                                   |&quot;
  echo &quot;=====================================&quot;
  
  timestamp=$( date +%T )
  echo &quot;$timestamp ==== Now uploading to store... &lt;br /&gt;&quot; &gt;&gt; &quot;$LOG_FILE&quot;
  </code></pre>