Reputation: 953
When calling a php file which contains:
<?php system('/bin/sh /usr/local/bin/myScript.sh '.'myArg'); ?>
from cli through php myScript.php
everything runs fine but when doing it through cgi, opening the url in the browser (apache in the background) myArg
string gets lost.
Does anyone knows what could be failing?
PD: myScript.sh is just an
echo "$# $*" >> /tmp/foo.txt
so a tail /tmp/foo.txt shows everything works fine from cli but not from apache's cgi. Do I need any extra configuration in php.ini? Do i need anything special in my apache alias file? Is it boodoo?
Upvotes: 0
Views: 158
Reputation: 17521
Make sure the user that runs apache has a shell in /etc/passwd
. Default user is nobody
.
Upvotes: 1
Reputation: 28906
If your code is as you listed it above, 'myArg'
will not be lost. However, if you are populating the argument dynamically, you will need to ensure that you collect the argument in a way that works appropriately for the calling method.
When you execute the script via a browser, you can collect arguments via $_REQUEST
, $_GET
, or $_POST
. When you execute the script via CLI, the arguments will be found in $argv
.
If you have verified that you get the correct value for the argument, the next step is to check permissions. Ensure that the CLI user has permissions to execute the command with the argument specified.
Upvotes: 1