I have shell script called copy.sh in my web root directory with following lines on it
rsync -rzv -e 'ssh -p 199' test.txt firstname.lastname@example.org:/home/testuser/txt ssh email@example.com -p 199 . /home/testuser/lty.sh > ltylog.txt 2>&1
This script first copy text file to my remote server and run the shell script to sync that file across other two servers. I generate ssh public/private key for testuser in my current server and copy to the remote server. I can ssh to remote server without any password
ssh firstname.lastname@example.org -p 199
I can run above command and can get in to my remote server. In my host machine when I'm in testuser I can execute that shell script without any issues. It copy the files and run the remote script. I set my script permission as 777 for now. But I need to run this script using PHP by running shell_exec like this
<?php shell_exec('. /var/www/html/copy.sh'); echo "<pre>"; echo file_get_contents("ltylog.txt"); echo "<pre>"; ?>
But when I run this PHP nothing happens. because I think the user who executing the shell script is Apache user instead of test user. but instead of running shell script when I shell_exec PWD or something it running flawlessly. I disabled the php safe mode and give 777 permissions for all the files. but still I can't get this worked.
P.S I know this is big security risk putting shell scripts on the web root with permissions. but this is not prod system and I'm testing small web application for our internal purposes. server I executing this has no internet access at all. could someone help me to fix this. I'm looking for small solution. since this small web app only used by one or two persons. thanks