pkromer
asked on
php script to run shell command
I have the following in a php file:
<?php
$output = shell_exec(dirname(__FILE_ _) . '/add_sku_to_get_flat_rate _quotes.sh ');
?>
When I call that file from a browser, it is supposed to run this .sh command in another file in same dir:
me@myserver:~/public_html/ mywebsite. com/symfon y$ app/console myaccount:get_flat_rate_qu otes sku 7017
Which is supposed to add that sku to a table. When I run that sh command from an SSH terminal, it works. What am I missing?
My web host confirmed shell_exec will work on my server.
<?php
$output = shell_exec(dirname(__FILE_
?>
When I call that file from a browser, it is supposed to run this .sh command in another file in same dir:
me@myserver:~/public_html/
Which is supposed to add that sku to a table. When I run that sh command from an SSH terminal, it works. What am I missing?
My web host confirmed shell_exec will work on my server.
suEXEC is normally required for a web / PHP user to run scripts with the owner's permissions instead of the generic web server permissions. https://en.wikipedia.org/wiki/SuEXEC Not all web hosts will enable it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, be sure to print $output + add a comment with whatever output was returned.
ASKER
php is working, I checked using the above snippet.
Setting the sh file to 777 didnt help, changing everything to absolute path didnt help, nothing helped. Are my two files above correct? Should the sh command look like it does? Do I have to prefix it with sh?
Setting the sh file to 777 didnt help, changing everything to absolute path didnt help, nothing helped. Are my two files above correct? Should the sh command look like it does? Do I have to prefix it with sh?
ASKER
finally got it... was just a tweak to my .sh file...
php file:
<?php
$output = shell_exec(dirname(__FILE_ _) . '/add_sku_to_get_flat_rate _quotes.sh ');
?>
.sh file:
/usr/home/me/public_html/m ysite.com/ symfony/ap p/console myaccount:get_flat_rate_qu otes sku 7017
php file:
<?php
$output = shell_exec(dirname(__FILE_
?>
.sh file:
/usr/home/me/public_html/m
ASKER
as David said, absolute path. I set it wrong before.
Depending on how your web host is set up, PHP is probably running from either a general web server user like "www" or "nobody" or it's a setup that does a setuid so the web server child process runs as your account.
Either way, the web server user probably doesn't have the same environmental variables / settings. If your shell script depends on any of them, then it will fail if they're not set.
If the web server runs as a generic user account, then maybe the shell script only has permissions to allow YOUR account to run it (or maybe it calls some other command that isn't accessible to a generic user).