Start / Stop and Restart Apache 2 Web Server Command

Posted on in Categories , , , last updated May 7, 2015

How do I restart an Apache 2 Web Server under a Debian / Ubuntu Linux or UNIX-like operating systems?

Apache is primarily used to serve both static content and dynamic Web pages on the World Wide Web. Many web applications are designed expecting the environment and features that Apache provides.Apache can be started or restarted using any one of the following methods.

First, login to your web-server using ssh client, if server is not in your local data center:
ssh [email protected]
Once logged in type the following commands as per your Linux or Unix variant.

Debian/Ubuntu Linux Specific Commands

You can either use service or /etc/init.d/ command as follows

Restart Apache 2 web server, enter:

# /etc/init.d/apache2 restart
OR
$ sudo /etc/init.d/apache2 restart
OR
$ sudo service apache2 stop

To stop Apache 2 web server, enter:

# /etc/init.d/apache2 stop
OR
$ sudo /etc/init.d/apache2 stop
OR
$ sudo service apache2 stop

To start Apache 2 web server, enter:

# /etc/init.d/apache2 start
OR
$ sudo /etc/init.d/apache2 start
OR
$ sudo service apache2 start

CentOS/RHEL (Red Hat) Linux version 4.x/5.x/6.x or older specific commands

## Start ##
service httpd start
## Stop ##
service httpd stop
## Restart ##
service httpd restart

CentOS/RHEL (Red Hat) Linux version 7.x or newer specific commands

Most modern distro now using systemd, so you need to use the following command:
## Start command ##
systemctl start httpd.service
## Stop command ##
systemctl stop httpd.service
## Restart command ##
systemctl restart httpd.service

Generic method to start/stop/restart Apache on a Linux/Unix

The syntax is as follows (must be run as root user):
## stop it ##
apachectl -k stop
## restart it ##
apachectl -k restart
## graceful restart it ##
apachectl -k graceful
## Start it ##
apachectl -f /path/to/your/httpd.conf
apachectl -f /usr/local/apache2/conf/httpd.conf

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

21 comment

  1. Can some one help me..
    When apache server restart then apache service will not working it shows…

    Not Found
    The requested URL / was not found on this server.
    Apache/2.2.22 (Debian) Server at 192.168.1.39 Port 80

  2. Hi
    ?
    [email protected]:/home/jakub# /etc/init.d/apache2 stop
    [….] Stopping web server: apache2apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
    [ ok waiting .

  3. Bonjour,
    en utilisant la commande suivante :
    service httpd restart
    j’obtient le resultat suivant :
    Redirecting to /bin/systemctl start httpd.service
    Job for httpd.service failed. See “systemctl status httpd.service” and “journalctl -xe” for details.

    j’ai pas bien comprit ce resultat
    Pouvez vous m’aider svp
    merci

  4. Any one can help me for solve this problem occurred on centos vps(cpanel):

    Stopping httpd: [FAILED]
    Starting httpd: AH00526: Syntax error on line 12 of /etc/apache2/conf.d/modsec2.conf:
    ModSecurity: Failed to open the audit log file: /etc/apache2/logs/modsec_audit.log
    [FAILED]

Leave a Comment