Our server runs both a dev and prod version of a website. I have a bash script I can run from CLI once I sudo, but I can't run from PHP b/c of the user difference between instances. For example... if I want to compare our home.css, I can do this from cli:
diff -U 0 /home/devsite/www/_css/home.css /home/prodsite/www/home.css | grep -c ^@
It will return 0 if they're the same and non-zero if they differ.
In PHP I tried to do this:
<?php
$dev_home = "/home/devsite/www";
$prod_home = "/home/prodsite/www";
$old_version = $dev_home .'/_css/home.css';
$new_version = $prod_home .'/_css/home.css';
$output = shell_exec("diff -U 0 $old_version $new_version | grep -c ^@");
echo "<pre>$output</pre>";
It always returns 0 even if I know the files are not the same. If I go into CLI and su to the "devsiteuser" account, which is what shows when I run "whoami" from PHP, and run the top CLI statement, I see that I don't have permission for the files in /home/prodsite/
I get the issue, but I'm not sure of the solution. Should I sudo to a different user or is there some kind of permission I can change to allow it to do a comparison?