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

  • Home
  • SEARCH
  • 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 7167551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:35:58+00:00 2026-05-28T14:35:58+00:00

I have the following simple script to test the mkdir() function in PHP: <?php

  • 0

I have the following simple script to test the mkdir() function in PHP:

<?php
  $id = rand();

  $targetPath = $_SERVER['DOCUMENT_ROOT'] . '/sample_folder/' . $id .'/';
  mkdir(str_replace('//','/',$targetPath), 0755, true);
?>

Ideally, this would create a random folder each time the script is run under my web directory/sample_folder. Sample_folder has 755 permissions.

The issue I face is, I keep running into PHP: mkdir() Permission denied issues. My sample_folder permissions are currently set to chmod 755.

EVERYTHING I have read states not to chmod to 777 so please don’t suggest it.

For test purposes, chmod 777 the ‘sample_folder’ directory addresses the issue but again this poses security issues. Is there something else I am missing on how to make this work?

Of note: my PHP users on the system is “apache”;

I am running PHP 5.3.* and CentOS 5.5 on a Media Temple dedicated virtual server for reference. I have also looked through nearly every chmod question on SO and cannot seem to find a solution that matches my issue (with the exception of 777 suggestions).

edit

Running ls -la on my server returns:

drwxr-xr-x 2 ftphiddenname psacln 4096 Jan 26 11:24 sample_folder

final update

The answers provided were very helpful. For anybody looking for additional information, I came across this knowledge base article and while it is listed on Media Temple, I blieve the principles apply to any most similar configurations:

(dv):Resolve Apache permission errors

  • 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-05-28T14:35:59+00:00Added an answer on May 28, 2026 at 2:35 pm

    The reason for this is the script needs write permissions in sample_folder.

    I don’t know your actual set up, but I’m guessing your script is either running under world permissions or group permission which is 5 (read 4 + execute 1) since your current permissions are 755 (7 for owner, 5 for group and 5 for world). To write directories into that folder, your script will need write access. You can set this up more securely than 777 if you have access to chown directories. My advice would be to create a group called ‘webgroup’ or similar and place your webserver user into that group. Then, give the group write permissions (770) would be appropriate once you have that set up. In case you’re a little hazy on how the permissions work, the final setup would be:

    sample_folder: owned by root, group webgroup, 770 permissions
    add whatever user apache (or other webserver) is running as to webgroup

    EDIT:

    With more details available in the initial post, this means you would be adding the user ‘apache’ to webgroup. If you find this too difficult a setup or you do not have full permissions on the server to set this up then using chown as suggested elsewhere to let apache own the directory would work as well.

    For example: chown apache sample_folder

    This will make apache the owner of the folder, giving it access to write permissions (assuming it is still 755)

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

Sidebar

Related Questions

I have the following simple python test script that uses Suds to call a
i have the following simple script <input class=input type=text name=password style=color: #797272; value= <?php
Trying to get a simple test perl script working. Have the following files/folder structure
I have the following simple script for backing up my website files and db.
it is the problem, i can't undertand anyway. i have the following simple script
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
I have the following simple function: private void EnableDisable941ScheduleBButton() { if (this._uosDepositorFrequency.Value != null)
Let's say we have the following mega-simple Python script: print Initializing.... a=10 print Variable
I have the following very simple Ext JS 4 script which is supposed to
I have the following simple script on a page <!DOCTYPE html PUBLIC -//W3C//DTD XHTML

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.