≡ Menu

Start / Stop / Restart Apache Web Server Via SSH

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 server1.cyberciti.biz using the ssh client:
$ ssh user@server1.cyberciti.biz
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

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 6 comments… add one }

  • Adam Ziaja August 14, 2011, 7:39 pm

    ssh login@server pkill -HUP apache2

  • thomas henson September 19, 2012, 9:15 pm

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

  • Tim July 5, 2013, 3:50 pm

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

    /sbin/service httpd restart

    • Daniel DeHaan January 22, 2015, 10:18 pm

      Hello Tim,

      Your comment helped! Thanks!!!!

      /sbin/service httpd restart

  • Peter Kerekes April 21, 2014, 9:10 pm
    ssh -C -t user@server1.cyberciti.biz 'sudo su - root -c "
    /etc/init.d/apache2 status;
    /etc/init.d/apache2 stop;
    /etc/init.d/apache2 start;
    /etc/init.d/apache2 status;
    "
    
  • Savet September 9, 2014, 4:09 pm

    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

Leave a Comment