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?

ADVERTISEMENTS

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
6 comments… add one
  • Adam Ziaja Aug 14, 2011 @ 19:39

    ssh login@server pkill -HUP apache2

  • thomas henson Sep 19, 2012 @ 21:15

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

  • Tim Jul 5, 2013 @ 15:50

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

    /sbin/service httpd restart

    • Daniel DeHaan Jan 22, 2015 @ 22:18

      Hello Tim,

      Your comment helped! Thanks!!!!

      /sbin/service httpd restart

  • Peter Kerekes Apr 21, 2014 @ 21:10
    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 Sep 9, 2014 @ 16:09

    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 Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.