rams22 — 2009-05-20T06:04:18-04:00 — #1
When i call a shell script via a php script all the commands inside the shell script doesn't execute correctly (in my case the chmod, cp commands doesn't work properly) this happens when call to the php script is made via web browser, whereas when the same php script is called through command prompt all the shell script commands executes perfectly
PHP script Code below.
$output = exec ('bash auto_install.sh '.escapeshellarg($v1).' '.escapeshellarg($v2));
Shell script code below.
cp -R /Users/developer/Sites/master /Users/developer/Sites/$1
chmod -R 777 /Users/developer/Sites/$1
php /Users/developer/Sites/$1/install.php mysql localhost $1 root pulkit $1 admin $2 localhost/~developer/$1 create 1
Thanks in advance
logic_earth — 2009-05-20T06:18:39-04:00 — #2
Well you see, running the script from the command line will run the script as the user. But running the same script from Apache (I assume) will run the file as the Apache's user account. Two different permissions is, from what I gather, your problem.
rams22 — 2009-05-20T06:30:16-04:00 — #3
we use apache server, could you plz tell me how to find the apache's user account. How do we solve this issue?
kyberfabrikken — 2009-05-20T07:09:25-04:00 — #4
You can either: Change the file permissions for the files that your script must interact with, or use sudo to change user from within your script. Both are a security risk, unless you trust every process running under Apache (Eg. every single virtual host on the web server), but the latter is more severe.
rams22 — 2009-05-20T07:37:01-04:00 — #5
Thankyou for your reply, Sudo would require me to input the password, how can i do that in the shell script?
kyberfabrikken — 2009-05-20T08:17:31-04:00 — #6
Put the user in sudoers. Can't you change the file permissions instead? sudo basically gives the web server full access to the machine, making it very prone to hacking attempts.
An alternative (depending on what you're trying to accomplish), could be to store the task in the database and then let an offline script (cronjob) process it. That way, the webserver won't have to change privileges.
bhardesv — 2010-12-06T01:24:25-05:00 — #7
Hi I am having same proble. i.e. I am able to run shell script through PHP program when i run PHP program through command promt but when I run PHP program through web browser i am not able to run shell script.
Thanks in advance