How do I figure out what user & group Apache is running as?

22,414

Solution 1

Actually, you don't need access to httpd.conf:

ps aux | grep apache2
groups apache_user

should yield what You want

Solution 2

I was having some issue that leads me to another solution. But it only works when you have access to the configuration file

We can actually check the user and group in \etc\apache2\envars file. This is where Apache set the environments var and use it across application.

Look for this two lines:

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

Note this is just setting environment variables. The actual setting the apache to run as what user/group is actually in the \etc\apache2\apache2.conf

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

The location of the files might me different but you should get the idea.

Share:
22,414
ma11hew28
Author by

ma11hew28

Updated on July 09, 2022

Comments

  • ma11hew28
    ma11hew28 almost 2 years

    On DreamHost shared hosting, I'm setting up htpasswd, but Apache does not have permission to read the file. How do I give it permission? I want to either change the owner or group of the .htpasswd file instead of giving it insecure permissions. I don't think I have access to the httpd.conf file, so I can't use this method to find what user Apache runs as. Also, running top or ps aux only shows the processes I'm running but doesn't show the apache process.

    Based on the output from cat /etc/passwd and cat /etc/group, I'm guessing it's www-data.

    Well, I followed the instructions for Password-protecting directories on Dreamhost. It generated a directory with a .htpasswd file with the group dhapache and permissions 440. It also put a .htaccess file in there with under my group. For some reason, when I try chgrp dhapache test_file.txt I get chgrp: changing group of 'test_file.txt': Operation not permitted. So, I just moved the .htpasswd file that DreamHost generated to where I wanted it and edited the .htaccess file it generated, despite its warnings.

    • barti_ddu
      barti_ddu over 13 years
      yes, typically it's "www-data:www-data"
  • barti_ddu
    barti_ddu over 13 years
    Or better ps axo user,group,comm | grep apache
  • ma11hew28
    ma11hew28 over 13 years
    Thanks. That doesn't work on DreamHost, but I figured it out. See the last paragraph of the question.
  • barti_ddu
    barti_ddu over 13 years
    It is a bit strange that ps aux didn't work for You (since dreamhost itself declares it should wiki.dreamhost.com/PS_Optimization); however, glad You did it one way or another.
  • A T - student
    A T - student over 9 years
    ps aux does not always display group information ... use ps axo above.