Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Chmod question

  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post

    Chmod question

    I have created class that creates a subdomain and then CHMODS the directory from 755 to 777 so that I can move files over.

    Here is the problem that I run into. When I run this from a web browser it fails to CHMOD. If I run it from a terminal as SUDO it does it. Is there a way that I can do the CHMOD from the browser? It would be a heck of a lot easier to do it there then with a CRON job later

    My code is below if it helps any. The function I am working with is below

    PHP Code:

    private function setupFilesystem($domain)
        {
        

        
    define('SOURCE_FOLDER''removed');
    define('CORE_FOLDER''removed');
    define('DB_SERVER''localhost');
    define('DB_USER''removed'); // This user needs to have permission to create new DB and users
    define('DB_PASS''removed');
    define('DB_SOURCE''removed');
            
    // Copy all the files and folders to the account folder and prepare the config files
            
    $userFolder 'PATH_TO_SUBDOMAIN/'.$domain.'/';
        
        
    $chmod = `chmod -R 0777 $userFolder`;  //This fails when run from a browser
        
    $perms substr(decoct(fileperms($userFolder)),1);

        

            
            if(!
    $this->smartCopy(SOURCE_FOLDER$userFolder))
                die(
    'Error copying the files'); 
    //if the permissions are not set this fails otherwise works fine
            
        
        
    }





    private function 
    smartCopy($source$dest$options=array('folderPermission'=>777,'filePermission'=>777)) { 
        
    $result=false;
      
        
        if (
    is_file($source)) { # $source is file 
            
    if(is_dir($dest)) { # $dest is folder 
                
    if ($dest[strlen($dest)-1]!='/'# add '/' if necessary 
                    
    $__dest=$dest."/"
                
    $__dest .= basename($source); 
                } 
            else { 
    # $dest is (new) filename 
                
    $__dest=$dest
                } 
            
    $result=copy($source$__dest); 
            } 
        else if(
    is_dir($source)) { # $source is dir 
            
    if(!is_dir($dest)) { # dest-dir not there yet, create it 
                
    mkdir($dest); 
                } 
            if (
    $source[strlen($source)-1]!='/'# add '/' if necessary 
                
    $source=$source."/"
            if (
    $dest[strlen($dest)-1]!='/'# add '/' if necessary 
                
    $dest=$dest."/"

            
    # find all elements in $source 
            
    $result true# in case this dir is empty it would otherwise return false 
            
    $dirHandle=opendir($source); 
            while(
    $file=readdir($dirHandle)) { # note that $file can also be a folder 
                
    if($file!="." && $file!="..") { # filter starting elements and pass the rest to this function again 
                    
    $result=$this->smartCopy($source.$file$dest.$file$folderPermission$filePermission); 
                    } 
                } 
            
    closedir($dirHandle); 
            } 
        else {
            
    $result=false
            } 
        return 
    $result;


  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    your using it wrong,
    have a look here at the "php chmod" function: http://php.net/manual/en/function.chmod.php

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    It works just fine on CLI but not a browser.....I've tried the other way it does not work ethier

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    well, thats because your browser accesses the page via your web server, and the web server wont run that command.

    I use php chmod all the time and it works perfectly,

    PHP Code:
    chmod("/somedir/somefile"755); 
    ps; if your on shared hosting making sure that you have permission to run such commands.

  • #5
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    I tried this as well and it did not work

    PHP Code:
    $userFolder 'PATH_TO_SUBDOMAIN/'.$domain.'/httpdocs/';
        
        
    //$chmod = `chmod -R 0777 $userFolder`;
    chmod($userFolder0777);
        
    $perms substr(decoct(fileperms($userFolder)),1);

        echo 
    $perms

  • #6
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    what didn't work? did you get an error?
    did you check the permissions on the $domain folder after running this?

    also you didn't say, are you on shared hosting? that could be an issue.

  • #7
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    .......double post...

  • #8
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by angst View Post
    what didn't work? did you get an error?
    did you check the permissions on the $domain folder after running this?

    also you didn't say, are you on shared hosting? that could be an issue.
    I'm not getting an error it just returns false......Chmod only returns true or false so there shouldn't be an error. When I echo out the permissions it still gives me 755 instead of 777. I'm on a dedicated server doing this. I did check the domain folder for this and it is still 755. I think that it is the web server that does not have the right access to CHMOD. I don't know how to change that though or even check.
    Last edited by Jacobb123; 03-03-2010 at 09:14 PM. Reason: need more info

  • #9
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    hmm, and your sure that the pass it's using is 100% correct?

    to check which user owns apache ( if thats what your using ), have a look at the apache.conf

  • #10
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    I assume you meant path and not "pass" Yeah....I've verfied it a couple of times....actually I have not tried to verify it from within the script. Let me do that and see if it works.
    Last edited by Jacobb123; 03-03-2010 at 09:50 PM.

  • #11
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    sorry, typo. I meant "path"

  • #12
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    OK....so I took out all of my code and just did one operation to chmod the directory and it throws this error

    Warning: chmod() [function.chmod]: Operation not permitted in...

    So it appears that whatever user the web server is using is not allowed to make changes.

    I was under the assumption that if safe_mode was off then I would not have this problem.....

    How can I solve this issue?

  • #13
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    well, before we go that far, have to tried setting the permissions while creating the folder?

    PHP Code:
    mkdir("/path"0777); 

  • #14
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well...The problem is that I am creating the directory with the Plesk API....so it automaticly does the directory creation

  • #15
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    but I see it in your code?

    mkdir($dest);

    thats not it?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •