Start / Stop / Restart Apache Web Server Via SSH

in Categories , last updated February 14, 2011

How do I start / stop or restart Apache web sever via SSH (secure shell) under Linux or UNIX operating systems?

Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following command to login to remote server called using the ssh client:
$ ssh
Once logged in switch to the root user by typing su – and entering the root password, when prompted:
$ su -
To restart Apache 2 web server over the ssh, enter:
# /etc/init.d/apache2 restart
To stop Apache 2, enter:
# /etc/init.d/apache2 stop
To start Apache 2, enter:
# /etc/init.d/apache2 start
If you are using RHEL / CentOS / Fedora based server, enter:
# service httpd restart
To stop RHEL / CentOS / Fedora based Apache server, enter:
# service httpd stop
To start RHEL / CentOS / Fedora based Apache server, enter:
# service httpd start

A Note About apachectl Command

You can also use the apachectl command as follows to restart the apache server:
# apachectl -k restart

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 6 comments/add one below):

6 comment

  1. What if apache2 does not work. What directory should I be in to call the services httpd restart? I have tried it all.

  2. Want to note that in my version of centOS, I needed to preface “service” with /sbin/

    /sbin/service httpd restart

  3. ssh -C -t 'sudo su - root -c "
    /etc/init.d/apache2 status;
    /etc/init.d/apache2 stop;
    /etc/init.d/apache2 start;
    /etc/init.d/apache2 status;
  4. Bonjour,en voulant m’inscrire sur un site,apache 2 m’est apparu sur l’écran et je n’arrive pas à m’en défaire et je ne suis toujours pas dans le site voulu.Quelqu’un a eu un truc pareil ou peut m’aider???Mille mercis

    Have a question? Post it on our forum!