12

I installed Apache a long time a go as part of setting up the development environment on my laptop.

However, since I stopped it some months back, it no longer starts automatically on boot. I have this problem on my laptop at home AND on my laptop at work.

I both cases, I installed Apache in Ubuntu 10.10 some months ago, used it for several weeks without a glitch, but then one day I stopped it and now it no longer starts automatically. I tried running the update rc for it manually, but was told the init script is already in use.

However, starting/restarting it manually with

sudo service apache2 start/restart

works fine. In both cases, I let it be until after the upgrade to 11.04, because I hoped it would be solved by the new version. But it's not! I'd be grateful if someone can tell me how to have Apache start automatically once more.

5 Answers 5

12

Try to run

update-rc.d apache2 enable [list of run levels]

as root.

You may interested to read

man update-rc.d
3
  • 1
    Thanks a lot, I ran the command (with no list of runlevels, just the defaults), and it seems to work. Do you know why it seemed to stop working? I didn't fiddle around with the init scripts, I think I just stopped Apache from the command line - but I had no intention of stopping it permanently. :-) May 12, 2011 at 9:32
  • I have no any opinion why it is stopped working :) Maybe after update something start working not correct.
    – ignar
    May 12, 2011 at 19:24
  • Thanks, but it doesn't help. No matter how I call update-rc.d apache2 enable, apache stops running automagically again. I always have to start it manually. There seems to be no actual problems, as it always starts correctly when I do it manually. May 31, 2011 at 7:14
11

I'm adding this answer based on recent issues I encountered with the same symptoms.

First some background data:

  • Ubuntu uses scripts in the /etc/init.d/ folder to start/stop services.
  • Ubuntu uses symlinks to those /etc/init.d/ scripts, stored in the /etc/rc#.d/ folders, to start/stop services based on the "runlevel".
  • Symlinks that start with an "S" indicate that the service should be started.
  • Symlinks that start with a "K" indicate that the service should be stopped (killed).
  • Runlevel 1 executes the scripts symlinked in /etc/rc1.d/, runlevel 2 uses /etc/rc2.d/, and so on.
  • The default runlevel for Ubuntu is 2.
  • Installation of Apache essentially runs sudo update-rc.d apache2 defaults which creates the appropriate symlinks in the /etc/rc#.d/ folders.

So it seems that on my server something, or someone, at some point ran sudo update-rc.d apache2 disable which removed all the "S" symlinks and replaced them with "K" symlinks. Thus killing, or just not starting, Apache when initializing any of the runlevels.

My solution was just to re-enable Apache:

sudo update-rc.d apache2 enable

Now Apache starts/stops as expected when starting up or switching runlevels.

NB:

It's worth noting that just running sudo update-rc.d apache2 defaults again is insufficient because it sees that symlinks exist and considers that they are what is wanted. It just responds with:

System start/stop links for /etc/init.d/apache2 already exist.
3
  • 1
    Thank you! This was very valuable in troubleshooting my configuration.
    – reor
    Sep 9, 2016 at 21:36
  • 1
    I'm having this problem but this solution surprisingly didn't work. When I run sudo update-rc.d apache2 enable defaults it removes what I have and then puts it right back. I have K09apache2 in rc0, 1, and 6, and I have S91apache2 in rc2, rc3, rc4, rc5. service apache2 start works fine, but I have to do it after every restart since it won't start up automatically. mysql, on the other hand, always starts up fine. Jul 13, 2017 at 6:01
  • 1
    Those look right. You might want to open new question with the details of your specific problem and be sure to include relevant lines from your /var/log/syslog and /var/log/apache2/error.log. Message me with the link to the question and I'll see if I can help. Jul 13, 2017 at 8:05
3

In this case, I found out why Apache wouldn't start. I could not find a trace of this in the startup logs, only in the output printed to the screen on bootup.

But here you go: The last line in the script /etc/apache2/apache2.conf failed.

Why?

It says:

Include sites-enabled/

However, two of the sites I've set up are located in my own home directory - which is encrypted!

So, on bootup (during startup of Apache) these sites don't exist, and Apache fails and refuses to run.

Solution?

I've created a small script called "disable_sites" and symlinked it into /etc/rc0.d and /etc/rc6.d (shutdown and reboot):

#!/bin/bash

/usr/sbin/a2dissite vvsshop
/usr/sbin/a2dissite neoflex
/etc/init.d/apache2 reload

exit 0

I also made a script to re-enable the sites whenever I log in and added it as a startup program in my System Settings. So now it works!

So, I suppose the lesson here is that when Apache inexplicably fails to load during bootup and you can't find any errors in the logs or when starting the server manually, check if all the directories it needs are available. This could probably also be solved in some other way.

2
  • I am surprised you did not find any errors in the logs. I have in the past discovered that some Apache startup errors were not in the log file I expected, but in a log file for one of my virtual hosts. Could this be the case? Jul 14, 2011 at 9:17
  • apachectl configtest would have notified you about the lack of permissions to access the files, while running as daemon.
    – Anuga
    May 23, 2019 at 10:00
1

For others looking (googling) for this issue check that if you run:

chkconfig |grep httpd

you get

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

else do:

chkconfig httpd on

(sorry on ubuntu chkconfig equivalent is update-rc.d see Chkconfig alternative for Ubuntu Server?)

0

I had the same problem, and I am running Ubuntu 14 on a local Vagrant setup. I removed the /etc/apache2/sites-enabled directory and added a link to my home directory, which of course is mounted to my local drive according to the Vagrant configs.

Turns out apache was not seeing the directory because the resource was not mounted yet. I rewrote my provision on Vagrant to just copy sites-enabled directory instead of adding a symlink.

I also did sudo update-rc.d apache2 enable as suggested by Karl Wilbur to be sure apache init was enabled.

You must log in to answer this question.

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