14

How to check what is Apache user?

I need to give read write permission to it, for some directories in my web root and outside of thee web root directory, how can i do that?

Since I dont have proper idea of what Apache user is, I cannot answer my next question.

BuvinJ
  • 10,221
  • 5
  • 83
  • 96
tecman
  • 615
  • 4
  • 7
  • 13
  • Why do you need to give read/write permission to it when you don't know what it does in the first place? Can you add some more detail? – Pekka Mar 17 '11 at 17:41
  • Currently for my software to work well, I need to give 777 permission to the whole directory. But to avoid that, i was suggested to give apache user the correct permissions so that i can avoid doing 777. – tecman Mar 17 '11 at 17:48
  • what kind of server are you on? Do you have command line access to it? – Pekka Mar 17 '11 at 17:49
  • the server can be windows/linux..... The scenario is, I want to first check whether the concerned directories are writable by apache user programtically using php, and in case if they are not writable, then ask to user to give write permissions to the apache user...... so i want to know, what is apache user, how can i give write permissions to it, and how can i test it programatically..... i just found that there is some method in php called "is_writable" which i will be using. – tecman Mar 17 '11 at 17:53

6 Answers6

18

ps aux | egrep '(apache|httpd)' typically will show what apache is running as.

Usually you do not need to change the default user, "nobody" or "apache"

PPPPPPPPP
  • 660
  • 7
  • 14
6

At the very least you need to specify the OS you are using. Look in your httpd.conf for the "User" directive. It will tell you what user apache will run as.

Coalpaw
  • 181
  • 1
  • 3
  • Ok, I will look into it. In the meanwhile can you please check my last comment under my question? – tecman Mar 17 '11 at 18:01
  • BTW, I took a quick glance over the user directive in apache, but I did not get the concept properly, can you refer me some links? and Im not getting how to grant permission to that apache user, I mean what command will i write to do that – tecman Mar 17 '11 at 18:03
  • You can determine the user with php by running `exec('whoami')`; – Coalpaw Mar 17 '11 at 19:00
  • Note that "Group" is also defined along with user. They both default to "apache". – BuvinJ Oct 16 '15 at 13:54
4

The apache2 user can be found out as follows. Go to /etc/apache2/apache2.conf and look for User

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

To find out the value for APACHE_RUN_USER and APACHE_RUN_GROUP, check in /etc/apache2/envvars

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

You may try to use the following command to check it:

ps axo user,group,comm | egrep '(apache|httpd)'

Or further more (to extract exact username) via:

ps axo user,group,comm | egrep '(apache|httpd)' | grep -v ^root | uniq | cut -d\  -f 1
ps axo user,group,comm | egrep '(apache|httpd)' | grep -v ^root | tail -1 | awk '{print $1}'

For Apache group, use the following command:

ps axo user,group,comm | egrep '(apache|httpd)' | grep -v ^root | uniq | cut -d\  -f 2
kenorb
  • 155,785
  • 88
  • 678
  • 743
2

Answer 1: what is an Apache user and where it is defined

In my default http.conf file located under /etc/apache2/httpd.conf (this file location varies by OS ) om my MAC, apache user is _www ( default user name as it comes with apache download )

since I see this in my httpd.conf

User _www

Answer 2: how do I give this user the read write permission to a folder "foo"

check who owns foo, by doing ls -l
# Use chown command to make _www ( apache user ) own "foo" folder
chown _www foo
# user chmod +666 to make this "foo" folder read write accessible
chmod 666 foo

good two min read on permissions http://www.macinstruct.com/node/415

kay am see
  • 968
  • 1
  • 10
  • 17
1

Apache user is typically the user that the apache httpd server uses when running. It uses this "apache" user to avoid having to use a "human" user, and to avoid having to run as root.

Advantages of installing an "apache" user include not having to run as root, so during the handling of http requests, there is less risk in damaging and losing the entire operating system.

The only real disadvantage of having an "apache" user is that you need to make web presented content accessible to the "apache" user. That typically involves a combination of the unix commands chown, chmod, and sometimes various selinux commands.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138