mkdir is failing when script is called by apache, but not from shell???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boytheo
    New Member
    • May 2007
    • 1

    mkdir is failing when script is called by apache, but not from shell???

    Hi people,

    I'm trying to get a script to create a few directories on a webserver, and unzip a file or two.

    my script works fine locally, when accessed via shell.

    When accessd via apache, it fails :(

    What to do?

    Here's my code:

    mkdir($School, 0755);
    chdir($School) || die( "Cannot chdir (1)" );

    the $School directory does not exist! It was not made :( I checked the files on my hard disk, it was never created. But it WAS Created if I run the script locally.

    What must I do?

    BTW, the server I'mg oing to install on, I'm not sure how much privileges I'll be allowed on it. My client will help me all they can, as they aren't beaureaucratic, but it is a commercial web server and not based on my home computer, so I have less control over it.
  • prn
    Recognized Expert Contributor
    • Apr 2007
    • 254

    #2
    It's almost certainly a permissions issue. When you run the script (as yourself) it works, but when Apache tries to run the script (probably running as the user "nobody") it fails because "nobody" doesn't have write permission for the directory where you are trying to create the new directory.

    Check that out. You will probably need to change the file permissions or ownership of the upper directory.

    HTH,
    Paul

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      Greetings boytheo,

      It appears that you've cross posted on a lot of different forum sites. This is typically frowned upon and will often net you less help in the end because cross-posters notoriously do not come back and check for answers.

      Nevertheless, the answer is simple. The permissions for the directory you're creating under are inadequate for the user the apache server is running on. This is fixable.

      Whenever you do a mkdir command, include an "or die" as this will tell you when an error occurs.

      perldoc mkdir

      [CODE=perl]
      mkdir($School, 0755) or die "mkdir failed: $!";
      [/CODE]

      - Miller

      Comment

      Working...