CentOS Apache – httpd Running as Both Root and Apache User

apache-2.2centoshttpdlinux

I have an Apache httpd server running on my CentOS server, but apparently it both runs a httpd-process as root and one as the apache user.

See this screenshot of top:

enter image description here

User and group are set to apache in the configuration file, so I'm kind of lost here.

Do any of you know what starts the "root" process, and why it's running?

Best Answer

The one running as "apache" is the worker process. The one running as "root" is the master process. This is completely normal.

The master process will spawn workers as necessary (with whatever constraints are specified in the configuration file) to handle incoming traffic. It typically will need to be root in order to bind to low ports 80 and 443. After it binds, it will drop privileges to the apache user.

Workers will be reaped from time to time. The long-running process is the one running as root. If you look at httpd.conf, you'll see a block that looks something like:

StartServers       1
MinSpareServers    1
MaxSpareServers    5
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000

So, the master process will spawn one worker in this example on startup. If there's more traffic, it will spawn more workers. Once workers serve 4000 requests, the worker will die, and the master process may spawn new worker processes, depending on traffic.