Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:18:54+00:00 2026-06-07T09:18:54+00:00

We are using a linux dedicated server in our company. Whenever we create a

  • 0

We are using a linux dedicated server in our company.

Whenever we create a folder with php script, apache is owning the folder and each time I have to connect to server via root in order to change the owner to the user and the permissions

But I don’t know which setting I should change in order to fix this.

I tried to switch the safe mode on/off but it didn’t work.

I’d be glad if someone could help me

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:18:56+00:00Added an answer on June 7, 2026 at 9:18 am

    This is a portability issue and depends on your server configuration (i.e. mod_php or FCGI with SuExec).

    You can try using the chown function right after you created the file, but that will only work if you know who the actual owner should be (which is not always the case). To overcome this issue, I wrote a simple method that tries to find the best possible file mode that always assures reading and writing (as well as execution for directories) without giving excessive permissions:

    function xChmod($path, $chmod = null) // adapted from phunction
    {
        if (file_exists($path) === true)
        {
            if (is_null($chmod) === true)
            {
                $chmod = (is_dir($path) === true) ? 777 : 666;
    
                if (extension_loaded('posix') === true)
                {
                    $user = posix_getpwuid(posix_getuid());
    
                    if (array_key_exists('name', $user) === true)
                    {
                        $chmod -= (in_array($user['name'], explode('|', 'apache|httpd|nobody|system|webdaemon|www|www-data')) === true) ? 0 : 22;
                    }
    
                }
            }
    
            return chmod($path, octdec(intval($chmod)));
        }
    
        return false;
    }
    

    Basically, if you omit the second $chmod argument, it will use 0777 for folders and 0666 for files by default, however, if PHP is being run under a non-standard user, it will decrement the mode by 22, yielding 0755 for folders and 0644 for files. Bare in mind that this will only work for files that already exist, so if you’re creating a directory you’ll need to have additional precautions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP 5 on my dedicated linux server 5.2.6 (cli) (built: May
How we run php script using Linux bash? php file test.php test.php contains: <?php
I wrote this function in php to check user/pass against account on linux server.
I am using linux mint OS. I want to create my own menu (eg
I have two specs from two different hosts I am using: (a) Dedicated server
I am using linux, for the first time in my life. But I am
I'm currently using a linux server, we run a couple of web sites of
I just recently migrated from a linux host to a dedicated server with windows
Setup: Two linux (CentOS 6) servers connected back-to-back over a dedicated GigE link. Each
I am using Linux server through putty tool . Inside the linux server ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.