Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I built apache 2.4.2 on CentOS from source and now am trying to create an init.d script to go along with it. A friend gave me one script but it never outputted a success or fail and I disliked it. I found in the tar a httpd.init script file. It just needed the location of apache changed but besides that seemed like it would work. However, it fails to stop httpd. It will start just fine however. Below is my current script in /etc/init.d/httpd. I found on this other topic: Restarting the httpd service in RHEL returns "Stopping httpd: [FAILED]" - How do I fix this? to check that a pid file is created in the /var/run directory but it is not being created there even when starting with service httpd start or the init.d script directly. I'm still fairly new to linux so please explain as much as possible. I'm a fast learner.

Can anyone help me find what's wrong with this script? I'm running CentOS 6.3 x86_x64.

share|improve this question
up vote 0 down vote accepted

What I dislike about your script (but I`ve seen this many times in distribution supplied ones, too) is that the location of the httpd-pid-file is somewhat hard-coded.

This is probably your problem here. If that hard-coded location and filename does not match the httpd configuration (there is the directive PidFile in httpd.conf) your killproc will do nothing intelligent.

So either you should parse your config-file for PidFile and fall back to the compiled-in standard, or use apachectl (with your config-file as parameter) for stopping httpd.

IMHO the latter is better and also covers the case where the pid-file has vanished (by accident).

share|improve this answer
I forgot to mention that I changed the lines: apachectl=/usr/sbin/apachectl and httpd=/usr/sbin/httpd to reflect the correct location of those files. As I see the script does have the apachectl location how do I change it to use apachectl instead? Also in my httpd.conf (/etc/httpd/conf/httpd.conf) there is no line for PidFile? (EDIT: I didn't write this, it's from the site I posted.) – Dustin Jul 28 '12 at 20:15
Okay so I added the PID file directive (/var/run/ is the path now) But I'm still wondering how I change it to use the apachectl? – Dustin Jul 28 '12 at 20:34
@Dustin look at the stop function. It uses killproc and the pid-file. Use $apachectl -k stop -f $configfile instead (look at man apachectl for details). This is propably much better than fiddling around with PID-files. But you have to define the configfile instead. – Nils Jul 28 '12 at 20:47
thank you, I'll try it out in a few hours. This seems promising. Could you just tell me how to define the config file? I'm having a very hard time trying to understand how these files work. – Dustin Jul 28 '12 at 20:54
@Dustin configfile=/etc/httpd/conf/httpd.conf just below the definition of apachectl - set it to wherever your config resides. – Nils Jul 28 '12 at 20:58

Have you tried init.d script from httpd packages for latest Fedora?

share|improve this answer
I didn't. I found one script in the source I downloaded from Apache. It wasn't working either but was similar. – Dustin Jul 28 '12 at 20:17
At least, your httpd should work with default config file (httpd.conf) and initscript from there. – Denis Jul 28 '12 at 20:22
Everything but starting seems to work. – Dustin Jul 28 '12 at 20:27
What does it say during start? Any errors? – Denis Jul 28 '12 at 20:34
I'm sorry I meant stopping. It starts just fine. I have a lot on my mind at the moment. I can't remember it saying any errors. I'll get back on that. – Dustin Jul 28 '12 at 20:56

Remi has httpd 2.4.2 in his github repo, though he doesn't seem to have built it yet (or it doesn't yet work) as I don't see RPMs for it yet. But you may be able to take his stuff and build RPMs.

share|improve this answer
Thanks I'll take a look – Dustin Jul 30 '12 at 3:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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