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 8201877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:58:00+00:00 2026-06-07T06:58:00+00:00

Solved I figured out who the current user was using PHP and managed to

  • 0

Solved

I figured out who the current user was using PHP and managed to set the new directories’ owner to be the user the PHP scripts are executed from. However, this was still causing issues as some other commands (used to determine who the current user was) weren’t working. This highlighted that the problem was that my PHP distribution was configured to be in safe mode.

I disabled safe mode and the commands provided by Ed Manet allowed me to add/edit/remove the files as desired, without the shortcut of just having everything be 777 permissions.

Thanks for the help!

Original Post

I have a web application that stores some data on the server. This involves creating and removing both directories and files (as well modifying existing files) in PHP. The main problem I’m having is do with the permissions required to perform such actions.

If I set existing files’ permissions to 777, then the PHP script can edit them just fine (although I know this isn’t an optimal solution as it’s insecure). The script can also create and remove directories just fine (when they have 777 permissions at least), but no matter what I do I cannot get the script to create new files.

I’ve done some searching around and it appears that I need to elevate the PHP “user” to a user that has the required priviliges. However, when it comes to server configuration and permissions I’m essentially a beginner. How would I change to a different user to perform the required actions? Is it possible to do this mid-script and use PHP’s fopen() and chmod() functions as normal? Or would I have to spawn an entirely new process using a shell command, somehow getting that external program executing with the correct privileges?

To summarise, I need a new of creating, modifying and deleting files/directories in a we b server using PHP, by assigning adequate permissions to the files and privileges to the PHP user. I am unsure on how to do this.

Thank you.

  • 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-07T06:58:02+00:00Added an answer on June 7, 2026 at 6:58 am

    What I would do is change ownership of the folder that the PHP has to create files in to the account that runs the PHP process. Then you don’t need to open up permissions so much.

    So if this is a Linux system and the webserver is run by a user called “apache”:

    chown -R apache /path/to/the/files
    

    Then change permissions to owner read/write

    chmod -R 644 /path/to/the/files
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out a way to find who a user mentions the
I've almost got this figured out by using previous questions, but I'm running into
SOLVED: Crap... why is it always you figure something out right AFTER you finally
So I'm trying to figure out the best way to solve simple logarithms using
Solved Hi currently im using SimpleXLSX to parse the xlsx (excel file), all the
Solved I actually found out what is going on here. Turns out it was
THIS PROBLEM IS NOW SOLVED. THANK YOU TO EVERYONE WHO REPLIED. Hello, I am
I'm using a text file to save the changes made by a user on
UPDATE OK, I figured it out. I had to call the following for varieties:
Edit: This has since been solved. Thanks to everyone who helped. Invoking the method

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.