12

I've got an Apache question here.

For my entire career as a developer, I've been restarting Apache like this:

sudo /etc/init.d/apache2 restart

I just today deployed my first Rails application, but I was having trouble getting Apache to restart on the host machine. When I tried it that way, Apache would try to restart, but would ultimately hang.

This, however, worked fine:

sudo apachectl restart

What are the differences between these two techniques? I had assumed that the latter was, at best, "syntactic sugar" for the first, but that must not be the case, given that the latter worked while the former did not.

If it's relevant (and I suspect it may be), this Rails application uses Phusion Passenger. My prior development experience (whereby the former method works fine) is mostly with PHP. I'm pretty new to Rails.

The server in question is runs Ubuntu 11.04 (Natty).

Ben Pilbrow
  • 11,995
  • 5
  • 35
  • 57
Chris Allen Lane
  • 333
  • 3
  • 12
  • 1
    Another alternative is service apache2 restart, although I'm not sure how that differs from the previous 2 if at all – Phil May 27 '11 at 22:29

1 Answers1

6
sudo /etc/init.d/apache2 restart

This method uses your Linux distro's init scripts to restart the process. These scripts are run at boot time to start apache.

sudo apachectl restart

This method uses the apachectl control program. In almost every occasion I would recommend the use of apachectl the to maniuplate the apache daemon. You have finer grained control over how the process restarts (see graceful vs. restart), configuration validation options and a way to get status information.

The main difference between using the init scripts to restart apache and apachectl is that apachectl is specifically designed to allow administators to control apache whereas the init scripts are designed as a generalized way for Unixes to start processes after the kernel and init daeamon have been loaded.

EDIT: Unfortunantly, I have no idea how to address your issue with Rails or Phusion Passenger. Try looking through your Apache logs for clues.

  • 2
    Exactly what do you think your OS is going to do when it reboots and your service apache2 start doesn't work? Using apachectl is fine for testing and dev work, but running servers that was is going to cause problems. Sticking it in rc.local isn't a solution either. – kashani May 27 '11 at 23:52
  • I should of mentioned that I'm only answering half of the question: the difference between the two methods for restarting apache. Unfortunately I don't know f'all about Rails... kind of speed-read over that on my first go around. –  May 28 '11 at 00:43
  • thanks for the help. That cleared up the differences between the two for me. Regarding the Rails stuff, I had actually solved that before I posted here. apachectl did in fact work like a champ, while the init.d method didn't. So now I know! Thanks. – Chris Allen Lane May 31 '11 at 00:28