title: Execute php file from bash script as www-data using crontab
body: <p>I am trying to run a php file every night at a certain time using crontab, however the php needs to be running as a www-data because of the directory permissions. To run it as <code>www-data</code> I am using the <code>root</code> crontab and changing the user in there, like so: </p>
  
  <p><code>* 20 * * * sudo -u www-data /usr/bin/env TERM=xterm /path/to/dailyProc.sh</code></p>
  
  <p>dailyProc is as follows </p>
  
  <pre><code>today=`date +"%d%m%y"`
  
  year=`date +"%y"`
  
  dm=`date +"%m%d"`
  
  `tar -zxf /path/to/input/$today.tgz -C /path/to/output`
  
  echo "starting data proc"
  
  `/usr/bin/php5 -f /path/to/dataproc.php date=$dm year=$year`
  
  echo "data proc done"
  </code></pre>
  
  <p>All other commands in dailyProc.sh work but the php doesnt run. The php is using an output buffer and writing it to a file, which works fine calling it from the command line but doesnt work when calling by cron. </p>
  
  <p>I can also definitely run dailyProc.sh from the command line as <code>www-data</code> using </p>
  
  <p><code>sudo -u www-data dailyProc.sh</code></p>
  
  <p>and everything works as expected. </p>
  
  <p>Is there any reason I would not be able to run this php file in <code>dailyProc.sh</code> using crontab when everything else in it works? </p>