Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I switched from SLES to Ubuntu and now I want to restart my local server. In SLES I used :

rcapache2 restart

but this somehow seems not to work in Ubuntu. :(

How do i restart my Apache?

share|improve this question

8 Answers 8

up vote 75 down vote accepted

Or sudo service apache2 restart for the way that's borrowed from Red Hat. Or sudo restart apache2 for the shiny new Upstart way.

share|improve this answer
    
I think service is the LSB way, and should work in most distributions, now that Debian and Ubuntu finally got it. –  Marius Gedminas Oct 12 '10 at 13:05
4  
sudo restart apache2 is not working in Ubuntu 12.04. Not sure of other Ubuntu versions. –  saji89 Jan 29 '13 at 7:42
    
@saji89 you need to do sudo service apache2 restart, then it will work. –  Kevdog777 2 days ago

The recommended way under Ubuntu to start/stop services (not just Apache) is to use the start/stop/reload commands (which really are symbolic links to the initctl program, part of upstart).

For services that use the legacy /etc/init.d scripts, the corresponding script will be called with the correct parameters; for services that use the upstart infrastructure, the appropriate event transition will be signaled to the upstart daemon via initctl.

So, to start/stop/reload/restart apache on Ubuntu, you can use:

sudo start apache2
sudo stop apache2
sudo reload apache2
sudo restart apache2
share|improve this answer

Do you want to restart Apache, or do you want to gracefully reload its configuration?

Everyone was answering the first question; you can do the second with

sudo apache2ctl graceful

or

sudo /etc/init.d/apache2 reload

Gracefully reloading is a bit faster, and there's no downtime. There's one caveat: if your apache config files contain an error, the server will silently exit without printing any error messages to the console.

share|improve this answer
    
Yes! Use graceful is much better if you want to restart without kicking off your web site viewers! –  tommed Oct 12 '10 at 13:33
    
I find that it's an advantage of restart that if Apache isn't running then it will start. --> Will reload also start it? –  Torben Gundtofte-Bruun Jan 5 '11 at 8:06
    
I don't think so -- even worse, reload will stop a running apache if you make a syntax error in the config file. –  Marius Gedminas Jan 6 '11 at 20:19
sudo /etc/init.d/apache2 restart

Of course you can swap out restart for stop, start and (I think) reload

share|improve this answer
1  
When doing this under recent Ubuntu, you get a message about doing it the new way, although it will still carry out your the desired command. –  jfmessier Oct 12 '10 at 11:34
    
I didn't realised Apache had moved to Upstart yet. –  Oli Oct 12 '10 at 11:48

Ubuntu way:

sudo service apache2 restart|stop|start 
share|improve this answer

As Marius said graceful should be used either to restart:

sudo apache2ctl graceful

or

sudo apache2ctl graceful-stop

to stop Apache gracefully.

These commands wait until all requests for web pages have been served before restarting/stopping the web server so that your user's don't get half a web page.

share|improve this answer

Try this program :

http://apache-switch.webuda.com/

It’s very easy to use. You can turn on, turn off or restart apache server.

share|improve this answer

if you are root: (In Ubuntu root is disabled, I think, than use 'sudo' command!)

$ /etc/init.d/apache stop
$ /etc/init.d/apache start
$ /etc/init.d/apache restart
$ /etc/init.d/apache reload 

(If you used a2ensite or a2dissite, you have to reload your apache configuration)

share|improve this answer
    
root isn't disabled, it just doesn't have a password if you don't give it one yourself. –  Mikael Auno Oct 12 '10 at 11:05
1  
is //stop apache supposed to be a comment? if so, standard shell notation would be #stop apache, // doesn't work in bash –  Mikel Jan 24 '11 at 8:05
    
@MikaelAuno root account is disabled if it doesn't have a password –  T0xicCode Apr 16 '12 at 0:25
    
@xav0989 That's quite the matter of definition. Sure you can't directly log in as root, or log in as root in any way that requires root's password for that matter, but there are other ways to become root. Try for example sudo -i followed by whoami and you'll see that you are indeed logged in as root. Also, if you do ps aux | grep root you'll see that you already have lots of processes on your system running as root. So, arguably, root is not disabled. –  Mikael Auno Apr 19 '12 at 16:33
    
@MikaelAuno or sudo -E -s. By disabled I'm assuming that what was meant is that you can't directly login as root, but you can still run processes as root. –  T0xicCode Apr 19 '12 at 20:07

Your Answer

 
discard

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.