Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which user to run Apache as?

Status
Not open for further replies.

georgeocrawford

Technical User
Aug 12, 2002
111
GB
Hi,

I'm getting in a bit of a muddle here. I have a PHP script which makes a couple of shell commands, and collects the output.

One of the shell commands is to test if a given file is a Mac OS X alias. If it is, the shell returns the path that the alias points to. To do this, it uses an AppleScript subroutine.

The problem is that the Applescript uses some property (don't understand at all - something to do with WindowManager) which means it must be run under the same username as is currently logged in (i.e. me). However, Apache was set to run as so it couldn't run the script.

I changed httpd.conf to run Apache as me (myusername:admin), and the script worked on my test computer, running OS X 10.3. It also worked OK on the server, which runs OS X Server 10.2.

There is another problem. Another part of the script uses a shell command to search through a directory for certain files and record the results in a text file. On my test machine, this works fine. However, the server, which I set to run Apache as theadminusername:admin, can't perform the scan. It just writes a blank text file.

If it's important, the first shell call is
Code:
$alias_path = shell_exec("aliascheck $escaped_path");
which uses the aliascheck command I have put at /bin/aliascheck:

Code:
#!/bin/sh
if [ $# -eq 0 ]; then
  echo "Usage: aliascheck file1 file2 file3..."
  echo "  where alias1, alias2, etc are files."
  echo "  Each file will be tested to see if it is an alias."
fi

while [ $# -gt 0 ]; do
  if [ -f "$1" -a ! -L "$1" ]; then
    item_name=`basename "$1"`
    item_parent=`dirname "$1"`
    # Next two rows should be entered as one row #
    item_parent="`cd \"${item_parent}\" 2>/dev/null && pwd || echo \"${item_parent}\"`"
    item_path="${item_parent}/${item_name}"
linksource=`osascript<<EOS
tell app &quot;Finder&quot;
set theItem to (POSIX file &quot;${item_path}&quot;) as alias
if the kind of theItem is &quot;alias&quot; then
get the posix path of (original item of theItem as text)
end if
end tell
EOS`
    if [ $? -eq 0 ]; then
      if [ ! -z &quot;$linksource&quot; ]; then
        echo &quot;${linksource}&quot;
      fi
    fi
    shift
  fi
done

The second shell call is this:

Code:
shell_exec('find ' . $escaped_root . &quot; \! -name '.*' -print | perl -p -e 's/&quot; . $double_escaped_root . &quot;\///g; ' | perl -p -e 's/&quot; . $double_escaped_root . &quot;\n//g; ' > &quot; . $escaped_data_folder . 'old.txt');

(don't worry about the variables in here, $escaped_root is the path to the root folder for the search, $double_escaped_root is $escaped_root with all / changed to \/ for perl, and $escaped_data_folder is the path to the folder where I store the text file)

Can someone suggest why this doesn't work on the server? If I type the command directly into the terminal, it works fine, so it's obviously a problem with the user Apache runs as.

Which user should I run Apache as to make both shell commands work?

______________________

George
 
Who owns the folder you are trying to list? Be careful, working around security to make things work could open up potential holes/exploits...

B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top