≡ Menu

Ubuntu Linux: Start / Restart / Stop Apache Web Server

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:
  1. systemctl command – Only works on systemd based Ubuntu like version 16.04 LTS and above.
  2. /etc/init.d/apache2 – A sys v init style script to start / stop / restart the Apache2 service under Debian or Ubuntu Linux.
  3. service command – This command work in most Linux distributions including Debian and Ubuntu.
  4. upstart command – Only works on certain version of Ubuntu.
  5. apache2ctl command – This method should work on all Linux and Unix like operating systems.

Method #1: systemctl command examples

To start Apache 2 on Ubuntu Linux LTS 16.04 LTS or the latest systemd based Ubuntu Linux, type:
$ sudo systemctl start apache2.service
To stop Apache 2 on Ubuntu Linux LTS 16.04 LTS or the latest systemd based Ubuntu Linux, type:
$ sudo systemctl stop apache2.service
To restart Apache 2 on Ubuntu Linux LTS 16.04 LTS or the latest systemd based Ubuntu Linux, type:
$ sudo systemctl restart apache2.service
To status of start/restart/stop operation, enter:
$ journalctl -u apache2
To find out whether Apache 2 running or not, enter:
$ sudo systemctl status apache2.service
Sample session:

Fig.01: Ubuntu Linux systemctl start/stop/restart Apache server (systemd)

Fig.01: Ubuntu Linux systemctl start/stop/restart Apache server (systemd)

Method #2: /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 #3: 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 #4: upstart command examples

The following commands only works with certian version of Ubuntu such as Ubuntu Linux LTS 12.04 and 14.04. 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 #5: 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

Sysadmin because even developers need heroes!!!

Share this tutorial on:
{ 25 comments… add one }
  • gzip June 25, 2009, 4:59 am

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

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

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

    Thanks for the tip. It worked like a charm.

  • Marco March 18, 2010, 3:51 pm

    thanks man

  • pingloopback November 4, 2010, 12:48 am

    These cmd line works great!!!!

  • John December 14, 2010, 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

  • man February 27, 2011, 8:16 am

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

  • ffadly April 7, 2011, 10:44 pm

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

  • murugesh June 7, 2011, 9:26 am

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

    • unnikrishnan June 28, 2011, 4:35 pm

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

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

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

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

  • Maurílio August 17, 2011, 6:38 pm

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

  • Hemant Thorat January 3, 2012, 6:05 am

    sudo service apache2 restart

  • yaasin February 29, 2012, 3:10 am

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

  • gagan March 26, 2012, 11:23 am

    awesome site………

  • Oz April 25, 2012, 11:36 am

    Thanks for the help.

  • mark May 7, 2012, 3:16 pm

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

  • Ibrahim Musa November 1, 2012, 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

  • Nanhe Kumar June 19, 2013, 11:27 am

    Your can also use this command
    sudo service apache2 restart

    • maan81 November 21, 2013, 3:15 pm

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

      PHP Cli uses a different php.ini .

  • tom August 4, 2013, 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.

  • Ankit Shah April 10, 2014, 4:04 am

    Nice tutorial. Help a lot :)

  • Craig Hubley May 24, 2016, 6:09 pm

    If you get “command not found” then apache2 may have been installed in a non-standard directory. For instance the bitnami installers put it in ‘stack’, so to find the ctl.sh you may need to use

    sudo stack/apache2/scripts/ctl.sh restart

    Whether this actually solves your problem or not, I don’t know, but it doesn’t cause the error.

  • Craig Hubley May 24, 2016, 6:26 pm

    Also when using bitnami the command

    sudo stack/ctlscript.sh restart

    restarts every service bitnami installed, including apache, in a logical order.

  • Craig Hubley May 24, 2016, 6:42 pm

    Final comment on this: If you are using one of the XAMPP or other stacks that installs apache as part of a larger package, you want to watch the stack-restart command (like the one I gave above for bitnami) very closely and always get the verbose log.

    If you have made some change like blowing away an app directory you aren’t using to fit within tight cloud host requirements, the configuration files generated for apache may be wrong/fragile and may cause apache to just not start with no indication why. However the stack-restart command for the stack you are using will generally report that problem. For instance in bitnami the restart is fragile – unless every single line of the configuration files it is relying on is up to date, you’ll have to go edit them yourself

    sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf

    PHP is however more robust and usually only generates a warning if it doesn’t find some app configuration include. The worst you will see from PHP is a line like this

    WARNING: Nothing matches the include pattern ‘/opt/bitnami/apps/limesurvey/conf/php-fpm/pool.conf’ from /opt/bitnami/php/etc/php-fpm.conf at line 17.

    so you can sudo nano that .conf file also, but it might be better to let all future shell users have at least a chance to notice that you blew away an app package and then manually reconfigured. I would leave the warnings in place myself. Your mileage may vary.

  • sam patel July 18, 2016, 9:22 am

    why we have to restart apache server in ubantu

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , , , , ,