0

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?

Don
  • 1,570
  • 4
  • 22
  • 38
  • php will be running with the permissions of the account that your webserver is running as. If the webserver can serve up files from the dev/prod directories, then PHP should be able to read the files as well. – Marc B Aug 29 '13 at 16:50
  • @MarcB not necessarily. It could be running as the Apache user. Or maybe I understood what you were saying. But it will likely run either as "apache" or as the owner of the website (assuming the server is Apache, of course) – Mike Aug 29 '13 at 16:50
  • See http://stackoverflow.com/questions/7771586/how-to-check-what-user-php-is-running-as – Mike Aug 29 '13 at 16:52
  • Runs as the name of the "devsiteuser" account. If I ran "whoami" from the prod it would be "prodsiteuser". Not sure if/how I can have the dev user look at prod's files to compare and if different move. – Don Aug 29 '13 at 16:56

0 Answers0