Start / Stop / Restart Apache Web Server Via SSH

by on February 14, 2010 · 4 comments· LAST UPDATED February 14, 2011

in

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 4 comments… read them below or add one }

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

ssh login@server pkill -HUP apache2

Reply

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.

Reply

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

Reply

4 Peter Kerekes April 21, 2014 at 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;
"

Reply

Leave a Comment

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

Previous Faq:

Next Faq: