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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:40:10+00:00 2026-05-22T00:40:10+00:00

I need to change the user of a PHP script at runtime. I’ve looked

  • 0

I need to change the user of a PHP script at runtime. I’ve looked at posix_setuid, but it looks unsecure and requires root privaledges. What would be preferable is changing the user id of the script with the users password (something like posix_setuid($username, $password)), and avoiding running the script as root.

I’m open to other methods, and the script doesn’t necessarily need to be PHP. However, it is going to be called from apache.

A good anology to the scenario would be how cPanel su’s to the currently logged in user on it’s file manager.

I need to change the user because I’m creating a file manager for a multi-user setup. Currently, I have the file manager set up so that apache serves my PHP file manager as root. However, this is not reasonable, because in case of a security bug in the code, one user can edit files on the entire server.

I’m looking for a way to SU the script to the logged in user so that in case of a security flaw, the user is only restricted to their own files.

  • 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-22T00:40:11+00:00Added an answer on May 22, 2026 at 12:40 am

    I needed to do this a while ago. I basically created a bash script which accessed resources that only root had access to. Here’s what I did:

    Use the visudo command to change your /etc/sudoers:

    ## Allow root to run any commands anywhere
    root    ALL=(ALL)       ALL
    apache ALL= NOPASSWD: /sbin/myscript.sh
    

    I have added the line which allows the apache user to run /sbin/myscript.sh with the sudo command without entering the password.

    After that, you can just put the following in your php file to get the output:

    $output = shell_exec("sudo /sbin/myscript.sh");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to change a user's password from a cron task
I need to store user entered changes to a particular table, but not show
I need to run a windows command line tool from a php script on
I Need to know if the user change the system time in the springboard
I need to change the font-size of some elements if the user is on
I need to change the DataTemplate for items in a ListBox depending on whether
I need to change the functionality of an application based on the executable name.
I need to change the capitalization of a set of files in a subversion
I need to change a static property on an object in our web application.
I need to change an element's ID using jQuery. Apparently these don't work: jQuery(this).prev(li).attr(id)=newid

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.