Start / Stop / Restart Apache Web Server Via SSH

by on February 14, 2010 · 6 comments· 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

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 6 comments… read them below or add one }

1 Adam Ziaja August 14, 2011 at 7:39 pm

ssh login@server pkill -HUP apache2


2 thomas henson September 19, 2012 at 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.


3 Tim July 5, 2013 at 3:50 pm

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

/sbin/service httpd restart


4 Daniel DeHaan January 22, 2015 at 10:18 pm

Hello Tim,

Your comment helped! Thanks!!!!

/sbin/service httpd restart


5 Peter Kerekes April 21, 2014 at 9:10 pm
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;


6 Savet September 9, 2014 at 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

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

Previous Faq:

Next Faq: