PHP - Shell_exec and exec returning false when ran
<p>I've done some extensive research on this topic. But I found nothing. It seems when I run shell_exec() it always returns false. Even when the output is true.</p>

<p>PHP script:</p>

<pre><code>$tmp1 = exec("/var/www/html/online/files/test.sh 2&gt;&amp;1");
</code></pre>

<p>test.sh Bash script:</p>

<pre><code>var=$(screen -ls | awk -F'[. ]' '/.onoff/ {print $1}')
if [ -z "$var" ]; then
  echo "false"
else
  echo "true"
fi
</code></pre>

<p>It's testing the screen PID for a screen called 'onoff' which was running at the time of being ran, yet still returns false. Even when I use the command in PuTTY it returns true.</p>

<p>Here are the permissions of the files:</p>

<pre><code>root@s94029:~# ls -la /var/www/html/online
drwxr-xr-x  3 root root 4096 Dec 18 12:34 .
drwxr-xr-x 12 root root 4096 Dec 18 09:30 ..
drwxr-xr-x  2 root root 4096 Dec 18 11:54 files
-rwxr-xr-x  1 root root  221 Dec 18 04:59 index.css
-rwxr-xr-x  1 root root 4310 Dec 18 12:55 index.php
-rwxr-xr-x  1 root root  417 Dec 18 06:40 servers.php
root@s94029:~# ls -la /var/www/html/online/files
drwxr-xr-x 2 root root 4096 Dec 18 11:54 .
drwxr-xr-x 3 root root 4096 Dec 18 12:34 ..
-rwxr-xr-x 1 root root  115 Dec 18 11:54 test1.sh
-rwxr-xr-x 1 root root  114 Dec 18 11:54 test.sh
</code></pre>

<p>Any help would be nice!</p>

<p>Thanks!</p>