23

So I just installed Apache on a new CentOS 7 server, using Yum. I've installed Apache many times before, but never have I seen this: When I run ps aux now, it always shows

/usr/sbin/httpd -DFOREGROUND

Google tells me that means the process will run in the foreground and not detach from the shell, but I don't really get what that means - if I close my shell, will Apache die?

I just want to get the normal Apache behaviour, and have httpd run like it always used to, chugging along in the background, do I need to disable DFOREGROUND? (I can't figure out how to btw)

5
  • 1
    And how did you start Apache? Jul 22, 2014 at 1:45
  • It happens if I do 'service apache start' or when the server starts and it loads the init.d/httpd script.
    – Cocorico
    Jul 22, 2014 at 2:05
  • What "init.d/httpd" script? You shouldn't have any such script. Jul 22, 2014 at 2:08
  • Michael: I copied one over from my old server cause I couldn't figure out another way to get it to start at startup. What should I be doing instead?
    – Cocorico
    Jul 22, 2014 at 14:00
  • 1
    systemctl enable httpd. See the documentation Jul 22, 2014 at 14:01

1 Answer 1

28

The -DFOREGROUND option does indeed mean that Apache won't fork, but that doesn't mean that it's attached to your shell!

The service is started by systemd when you run systemctl start httpd (or the old style way, service httpd start). It is systemd to which Apache is attached, and systemd is managing the process as one of its children. This is done so that systemd can easily tell whether Apache has crashed, without having to poll a pid file or do other nasty hackery. This also means that systemd is capable of automatically restarting Apache if it does crash.

Run systemctl status httpd to see its status. An example looks like:

# systemctl status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since Sat 2014-07-12 01:53:50 UTC; 1 weeks 3 days ago
  Process: 21400 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 390 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─  390 /usr/sbin/httpd -DFOREGROUND
           ├─15379 /usr/sbin/httpd -DFOREGROUND
           ├─15858 /usr/sbin/httpd -DFOREGROUND
           ├─16809 /usr/sbin/httpd -DFOREGROUND
           ├─16944 /usr/sbin/httpd -DFOREGROUND
           ├─17079 /usr/sbin/httpd -DFOREGROUND
           ├─17351 /usr/sbin/httpd -DFOREGROUND
           ├─17487 /usr/sbin/httpd -DFOREGROUND
           ├─17772 /usr/sbin/httpd -DFOREGROUND
           ├─17908 /usr/sbin/httpd -DFOREGROUND
           └─18043 /usr/sbin/httpd -DFOREGROUND

Jul 12 01:53:50 hozen httpd[390]: AH02559: The SSLCertificateChai...d
Jul 12 01:53:50 hozen httpd[390]: AH00558: httpd: Could not relia...e
Jul 12 01:53:50 hozen systemd[1]: Started The Apache HTTP Server.
Jul 13 03:30:02 hozen systemd[1]: Reloading The Apache HTTP Server.
Jul 13 03:30:02 hozen httpd[9332]: AH02559: The SSLCertificateCha...d
Jul 13 03:30:02 hozen systemd[1]: Reloaded The Apache HTTP Server.
Jul 21 03:19:02 hozen systemd[1]: Reloading The Apache HTTP Server.
Jul 21 03:19:02 hozen httpd[21400]: AH02559: The SSLCertificateCh...d
Jul 21 03:19:02 hozen systemd[1]: Reloaded The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
3
  • 3
    Thanks, that makes a lot of sense. So just to be sure I do understand though, it's fine then to run with DFOREGROUND and it's actually good, not bad, right?
    – Cocorico
    Jul 22, 2014 at 5:15
  • 4
    Yes, it's fine. Jul 22, 2014 at 5:40
  • 1
    @MichaelHampton Is there a way to see what exactly one of these process is running?
    – carla
    Oct 25, 2016 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .