2

I would like for Apache2 to start whenever the computer is booted. I'm using Ubuntu 13.10. To get Apache to start, I run this command in terminal:

sudo /usr/local/apache2/bin/apachectl start

I will probably need step-by-step directions.

Rmano
  • 31,627
  • 16
  • 118
  • 187
user217732
  • 31
  • 1
  • 2
  • 1
    my Apache server starts at boot. But I'm using a LAMP server... – Alvar Nov 21 '13 at 00:24
  • possible duplicate of [How do I start applications automatically on login?](http://askubuntu.com/questions/30931/how-do-i-make-a-program-auto-start-everytime-i-log-in) –  Nov 21 '13 at 00:45
  • 2
    @user123456: No --- the user wants to start the program at **boot**, not at **login**. Quite different beast. – Rmano Nov 21 '13 at 00:47
  • @Romano see http://askubuntu.com/questions/186865/how-do-i-start-a-program-automatically-when-i-boot –  Nov 21 '13 at 00:54
  • 3
    How did you install Apache? If not [from the repositories](https://apps.ubuntu.com/cat/applications/apache2/), why not? If you did install it from the repositories, how do you know it isn't already starting at boot? Please feel free to edit your question to include more information as necessary. – ændrük Nov 21 '13 at 00:56
  • 1
    @user123456: although you are right about the title of the question you cite, if you read the answers, the author really meant at login. This question is about system boot, really. – Rmano Nov 21 '13 at 01:07
  • possible duplicate of [How do I start applications automatically on login?](http://askubuntu.com/questions/48321/how-do-i-start-applications-automatically-on-login) – Aditya Dec 31 '13 at 14:44

1 Answers1

4

From the location of the command (/usr/local/...) it seems that you have compiled apache yourself, and not installed the distribution's package.

The startup of the httpd daemons should be controlled by either upstart or the System-V style script in /etc/rc.d.

The simple solution is to add the command to /etc/rc.local. This file is a script that is executed at the end of the booting process. Open the file in your preferred editor, for example

gksudo /etc/rc.local 

And add this before the line that read exit 0:

if [ -x /usr/local/apache2/bin/apachectl ]; then 
   /usr/local/apache2/bin/apachectl start
fi

The test should avoid to have an error in the boot phase that will stop the boot process if somehow you manage to remove the program forgetting to re-edit the file.

Rmano
  • 31,627
  • 16
  • 118
  • 187
  • 1
    @user217732: thanks, but the form of saying thanks in this site is to upvote and accept the answer... see http://askubuntu.com/help – Rmano Nov 21 '13 at 01:03