Aache 2.0 with subdomains & PHP- directory creation permission problems

Posted on 2005-04-20
Last Modified: 2008-02-20
I am running Apache 2.0 with subdomains. My application is PHP-based. When a user (anonymouse) uploads a file, the file is placed in a new directory with an owner of "apache". The image processing that is then supposed to occur under GD fails- until I change the directory owner to "site6". I am also using the Ensim Pro control panel under Fedora Core 2. Any way to have those directories set with an owner of site6 upon creation? Does PHP have the capability to set new file/directory permissions?
Question by:Thunnus
    LVL 5

    Accepted Solution

    Yep, chmod() -

    Try it, but I'm guessing you'll might have problems.  If it doesn't work, I think the quickest solution would be to make the users site1/site2/site3/etc. members of the apache group.  Then, you'll probably be able to do a chown() on the file to change it's ownership to the current user -  If you have problems getting chown() to work (i.e. it still says you don't have permission) then you might have to change the umask for your apache user.  The umask handles the default permissions when files are created.  I'm not sure *exactly* where you'd use it, but php also has a umask() function -  I would guess you'd put it at the top of the page where the files are actually handled after they're uploaded.  I'm thinking you'd probably do something like this:


    ... handle file upload

    foreach($uploaded_files as $file) {
        chown($file, "my_user");
        // if you want only this user to have access this file:
        chmod($file, 0700);

    Anyway, I hope that at least gives you some more insight into your problem.
    LVL 14

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
    I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: dougday

    Any objections should be posted here in the next 4 days. After that time, the question will be closed.

    EE Cleanup Volunteer

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now