Ubuntu Linux: Start / Restart / Stop Apache Web Server

by on February 6, 2008 · 21 comments· LAST UPDATED November 2, 2013

in , ,

How do I start, restart, or stop Apache 2.x web server on Ubuntu Linux operating systems using command line options?

You can use any one of the following method to restart / start / stop your Apache (httpd) sever on Ubuntu:

Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsShell
Estimated completion time1m
  1. /etc/init.d/apache2 - A sys v init style script to start / stop / restart the Apache2 service under Debian or Ubuntu Linux.
  2. service command - This command work in most Linux distributions including Debian and Ubuntu.
  3. upstart command - Only works on latest version of Ubuntu.
  4. apache2ctl command - This method should work on all Linux and Unix like operating systems.

Method #1: /etc/init.d/apache2 command examples

You need to login as root user or use the sudo command to control Apache web-server.

Task: Start Apache 2 Server

# /etc/init.d/apache2 start
or
$ sudo /etc/init.d/apache2 start

Task: Restart Apache 2 Server

# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart

Task: Stop Apache 2 Server

# /etc/init.d/apache2 stop
or
$ sudo /etc/init.d/apache2 stop

Method #2: service command examples

To restart Apache 2, enter:
$ sudo service apache2 restart
To stop Apache 2, enter:
$ sudo service apache2 stop
To start Apache 2, enter:
$ sudo service apache2 start
To gracefully reload Apache 2, enter:
$ sudo service apache2 reload

Method #3: upstart command examples

To start Apache 2 on Ubuntu, run:
$ sudo start apache2
To stop Apache 2 on Ubuntu, run:
$ sudo stop apache2
To restart Apache 2 on Ubuntu, run:
$ sudo restart apache2
To gracefully reload Apache 2 on Ubuntu, run:
$ sudo restart apache2

Method #4: apache2ctl command examples

apache2ctl is Apache HTTP server control interface command, which can be used to stop or start web server under any Linux distribution or UNIX.
To start Apache 2 on Ubuntu, type:
$ sudo apache2ctl start
To stop Apache 2 on Ubuntu, type:
$ sudo apache2ctl stop
To restart Apache 2 on Ubuntu, type:
$ sudo apache2ctl restart
To gracefully reload Apache 2 on Ubuntu, type:
$ sudo apache2ctl graceful

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 21 comments… read them below or add one }

1 gzip June 25, 2009 at 4:59 am

Edit ~/.bash_profile and add:
alias apache='sudo /etc/init.d/apache2'

Then it’s just apache start, apache restart, etc.

Reply

2 Ricardo Soares de Lima February 2, 2010 at 1:55 am

Thanks for the tip. It worked like a charm.

Reply

3 Marco March 18, 2010 at 3:51 pm

thanks man

Reply

4 pingloopback November 4, 2010 at 12:48 am

These cmd line works great!!!!

Reply

5 John December 14, 2010 at 12:52 am

Here is what works for me:

/etc/rc.d/init.d/httpd (space) start

or

/etc/rc.d/init.d/httpd (space) stop

Reply

6 man February 27, 2011 at 8:16 am

nice tutorials,
is there a way to run the apache server as services just like in xampp?
Thanks,
man

Reply

7 ffadly April 7, 2011 at 10:44 pm

wohooooooo,,,, good tutorial ,,, 4 thumbs ^_^

Reply

8 murugesh June 7, 2011 at 9:26 am

it s not workin for me….
the result is
sudo: /etc/init.d/apache2 commad not found
pls help me guys

Reply

9 unnikrishnan June 28, 2011 at 4:35 pm

sudo /etc/init.d/apache2 do not put that column after sudo

Reply

10 blog for note June 10, 2011 at 3:53 pm

i has stop my apache server, but another connections still establish

unix 3 [ ] STREAM CONNECTED 14940 /tmp/orbit-username/

Reply

11 MaurĂ­lio August 17, 2011 at 6:38 pm

I’m from Brazil, and your tip helped me a lot, thanks!

Reply

12 Hemant Thorat January 3, 2012 at 6:05 am

sudo service apache2 restart

Reply

13 yaasin February 29, 2012 at 3:10 am

Thanks mate! nice and easy ( I like the easy ones!)

Reply

14 gagan March 26, 2012 at 11:23 am

awesome site………

Reply

15 Oz April 25, 2012 at 11:36 am

Thanks for the help.

Reply

16 mark May 7, 2012 at 3:16 pm

the amount of times i forget this. sheesh. thanks gzip

Reply

17 Ibrahim Musa November 1, 2012 at 3:45 pm

Hi! this tutorial is great. things have been ok but mine didnt work at the configuration stage. i restart the server but this d response:
Restarting web server apache2 apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
… waiting apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
help me pls

Reply

18 Nanhe Kumar June 19, 2013 at 11:27 am

Your can also use this command
sudo service apache2 restart

Reply

19 maan81 November 21, 2013 at 3:15 pm

Does the “sudo service apache2″ apply for the php cli ?

PHP Cli uses a different php.ini .

Reply

20 tom August 4, 2013 at 10:27 pm

sudo service apache2 This worked for me, thanks a lot. I had an instance of apache2 running, but it was screwing up apache that was trying to run in xampp.

Thanks again.

Reply

21 Ankit Shah April 10, 2014 at 4:04 am

Nice tutorial. Help a lot :)

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , ,

Previous Faq:

Next Faq: