title: Executing screen within a script fails when script is launched with PHP
body: <p>I am using php to execute a script on my server.<br>
  PHP: <code>exec("screen -dmS testingscreen /home/username/otherfolder/test.sh")</code><br>
  For a while I was unable to do this till I did some digging and found a few things about how to do this.  I also found some items about other things relating to screen / minor issues I was having at the same time.  </p>
  
  <p>I will show each issue I had in detail up to the last issue which I can not seem to figure out a fix.</p>
  
  <hr>
  
  <p>Issue one (Resolved): Trying to run script outside of webroot.<br>
  Topic: <a href="https://stackoverflow.com/questions/28445735/executing-shell-script-outside-of-webroot-from-php">Excute script outside of web root with PHP.</a><br>
  Solution: Used <code>sudo chown www-data:www-data filename.sh</code> giving my web user access to the script.    </p>
  
  <hr>
  
  <p>Issue two (Resolved): Script does nothing when php file invokes it.<br>
  Solution: Make script executable with <code>chmod +x filename.sh</code><br>
  Notes: It was painfully obvious what I did wrong when I used <code>ls</code> in my script dir.</p>
  
  <hr>
  
  <p>Issue three (Resolved): Unable to su to www-data to check if screens were running.<br>
  Error: This account is currently not available.<br>
  Problem: www-data was set to <code>/bin/nologin</code> in <code>/etc/passwd</code><br>
  Solution: <code>chsh -s /bin/bash www-data</code> to make it so I can switch to it as user.</p>
  
  <hr>
  
  <p>Issue four (Resolved): While in <code>su www-data</code> could not use <code>screen -r testingscreen</code><br>
  Error: Cannot open your terminal '/dev/pts/0' - please check.<br>
  Problem: Permissions, not opening screen under login account and trying to use su account.<br>
  Solution: Using <code>script /dev/null</code> in terminal before trying <code>screen -r testingscreen</code>.</p>
  
  <hr>
  
  <p>Issue five (Not Resolved):<br>
  While executing <code>screen -dmS testingscreen /home/username/anotherfolder/filename.sh</code><br>
  With php's <code>exec()</code> does make screen <code>testingscreen</code>  </p>
  
  <p>I have a line in the script file that says<br>
  <code>screen -dmS scriptscreen mono '/home/username/otherfolder/myprogram.exe' 'programargs1' 'programargs2' 'args3' 'args4'</code><br>
  This screen fails to run when executed with the script "filename.sh"<br>
  However executing this same line as the www-data user (Using <code>sudo su www-data</code> to be that user.) works fine.</p>
  
  <p>Also of note:  Running <code>screen -dmS testingscreen /home/username/otherfolder/test.sh</code> works absolutely fine and starts up like it should including <code>scriptscreen</code>. This works while using <code>sudo su www-data</code> but not if I start the script with php.</p>
  
  <p>On the more bizarre side of this, using <code>screen -dmS testingtop top</code> works fine when inside the script file that is started by php.   Am I missing something obvious here?</p>
  
  <p>I have checked file permissions and everything is fine, it should work.  Being able to run my program as www-data means that the perms are set up fine. It just seems like it's something to do with php or my server in general.  Any help or possible tips are very welcome and I hope my detailed issue+solution write up may help others in the future all in one post.</p>