Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Need help to create a new user to apache web server and assign root privileges to newly created user. Or how to login as root user in apache server because following php script showing you are logged in as

nobody.

< ?php echo whoami; ?>

share|improve this question
    
This one probably belongs to either ServerFault or StackOverflow. –  Hippo Mar 26 '12 at 18:00
    
forum.mamp.info/viewtopic.php?t=372 I'll write this as an answer if it's what you're looking for. –  Andrew Latham Mar 26 '12 at 18:02
    
@Hipp0 - not StackOverflow –  Mark Mar 26 '12 at 18:28
    
@Mark if not StackOverflow then?? I am logged in in system as root. I started xampp server as root e.g: sudo /opt/lampp/lampp start. But When I execute < ?php echo whoami; ?> it shows me nobody instead root......... –  Alee Mar 26 '12 at 18:35
2  
Try ServerFault - note that nobody is the correct result - so that apache by default has no permissions to affect the system –  Mark Mar 26 '12 at 19:22
show 1 more comment

closed as off topic by gentmatt, Mark, Ian C., Kyle Cronin Mar 27 '12 at 17:18

Questions on Ask Different are expected to relate to Apple hardware or software within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

There really isn't a good reason to run your web server as root. It opens you up to all kinds of potential abuse. OS X defaults to running the service as a severely under privileged user to protect you.

Don't make these changes unless you're absolutely certain you know what you're doing!

The httpd.conf file for the default Apache2 installation that comes with OS X can be found in /private/etc/apache2/httpd.conf. Before you make any changes to this file BACK IT UP! That way you can get back to a sane starting place if you make a catastrophically bad change.

Open the file in a text editor and look for the following lines:

# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch...
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User _www
Group _www

The _www user/group is the default for OS X. If you want to run the server as root you'll need to change this to the appropriate user. For root:

User root
Group wheel

The plist that describes the Apache service to launchd is at /System/Library/LaunchDaemons/org.apache.httpd.plist -- OS X runs any launchd runs daemons described in this location as root so the server starts with sufficient privledges to change context to another user.

Once you've made the changes, restart Apache with:

sudo /usr/sbin/apachectl restart

and you should be running as root.

Again: BE CAREFUL DOING THIS!

share|improve this answer
    
Sir it was glad for me to see your answer. I am using ubuntu server 11.10. I understand the risk to run apache as root, but I am a student so wants to gain more and more knowledge. I have installed xampp server in /opt and my httpd file is in /opt/lampp/etc. By following your answer I editted the httpd file. –  Alee Mar 27 '12 at 17:02
    
In ubuntu we have nobody as default user and group. So following your answer I have changed nobody to root in both user and group. The secong step: /System/Library/LaunchDaemons/org.apache.httpd.plist , I couldn't understand. I have searched plist in my /opt directory but I couldn't found. Instead of plist I found PropList.txt. –  Alee Mar 27 '12 at 17:02
    
@Alee my plist stuff only applies if you're running on OS X. Skip that for Ubuntu. This got posted on AskDifferent so it's implied you're using Apple OS -- hence my OS X-specific answer. –  Ian C. Mar 27 '12 at 17:08
    
Thank you so very much –  Alee Mar 27 '12 at 17:57
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.