How do I restart an Apache 2 Web Server under a Debian / Ubuntu / CentOS / RHEL / Fedora Linux or UNIX-like operating systems? Can you tell me command to start or stop Apache 2 web server running on Linux?
Tutorial details |
|---|
Difficulty level |
Easy |
Root privileges |
Yes |
Requirements |
Apache 2 on Linux / Unix |
Est. reading time |
4 mintues |
Apache is primarily used to serve both static content and dynamic Web pages on the World Wide Web. Many web applications are designed expecting the environment and features that Apache provides. Apache can be started or restarted using any one of the following methods on Linux or Unix-like systems.
First, login to your web-server using ssh client, if server is not in your local data center:
ssh root@your-server-com #Linode box
ssh ec2-user@aws-ip-here # AWS
ssh vivek@192.168.2.100 # My home dev serverOnce logged in type the following commands as per your Linux or Unix variant.
Debian/Ubuntu Linux Specific Commands to Start/Stop/Restart Apache
You can either use service or /etc/init.d/ command as follows on
Debian Linux version 7.x or Ubuntu Linux version Ubuntu 14.10 or older:
Restart Apache 2 web server, enter:
# /etc/init.d/apache2 restartOR
$ sudo /etc/init.d/apache2 restartOR
$ sudo service apache2 restartTo stop Apache 2 web server, enter:
# /etc/init.d/apache2 stopOR
$ sudo /etc/init.d/apache2 stopOR
$ sudo service apache2 stopTo start Apache 2 web server, enter:
# /etc/init.d/apache2 startOR
$ sudo /etc/init.d/apache2 startOR
$ sudo service apache2 startA note about Debian/Ubuntu Linux systemd users
Use the following systemctl command on
Debian Linux version 8.x+ or Ubuntu Linux version Ubuntu 15.04+ or above:
## Start command ##
systemctl start apache2.service
## Stop command ##
systemctl stop apache2.service
## Restart command ##
systemctl restart apache2.serviceWe can view status using the following command:
$ sudo systemctl status apache2.service● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-02-24 20:39:39 UTC; 5 days ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 115 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Process: 15247 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 128 (apache2)
Tasks: 6 (limit: 4672)
Memory: 16.4M
CGroup: /system.slice/apache2.service
├─ 128 /usr/sbin/apache2 -k start
├─15254 /usr/sbin/apache2 -k start
├─15255 /usr/sbin/apache2 -k start
├─15256 /usr/sbin/apache2 -k start
├─15257 /usr/sbin/apache2 -k start
└─15258 /usr/sbin/apache2 -k start
Feb 27 00:00:23 ubuntu-db-mgmnt systemd[1]: Reloaded The Apache HTTP Server.
Feb 28 00:00:23 ubuntu-db-mgmnt systemd[1]: Reloading The Apache HTTP Server.
CentOS/RHEL (Red Hat) Linux version 4.x/5.x/6.x or older specific commands
## Start ##
service httpd start
## Stop ##
service httpd stop
## Restart ##
service httpd restartCentOS/Fedora/RHEL (Red Hat) Linux version 7.x or newer specific commands
Most modern RHEL based distro now using systemd, so you need to use the following systemctl command:
## Start command ##
systemctl start httpd.service
## Stop command ##
systemctl stop httpd.service
## Restart command ##
systemctl restart httpd.serviceThe above commands works with RHEL, CentOS, RockyLinux, Fedora, and AlmaLinux.
Alpine Linux start / stop / restart Apache 2 using openrc
We need to use the service command as root user:
# service apache2 start
service apache2 stop
service apache2 status
service apache2 restart
Session: * Stopping apache2 ...
* Starting apache2
FreeBSD Unix users
FreeBSD user can restart Apache as follows:
# /usr/local/etc/rc.d/apache22 restart
service restart apache22
service stop apache22
service start apache22
Generic method to start/stop/restart Apache on a Linux/Unix
First, use the type command or command command to find the apachectl or apachectl2 path:
type -a apachectl
type -a apache2ctlOutputs from the Ubuntu Linux 20.04 LTS server:
apachectl is /usr/sbin/apachectl
apachectl is /sbin/apachectl
Then use the syntax is as follows (must be run as root user):
## stop it ##
apachectl -k stop
## restart it ##
apachectl -k restart
## graceful restart it ##
apachectl -k graceful
## Start it ##
apachectl -f /path/to/your/httpd.conf
apachectl -f /usr/local/apache2/conf/httpd.confThe apachectl/apache2ctl is Apache HTTP server control interface. Other options are as follows:
Start the Apache daemon
apachectl start
OR
apache2ctl startStops the Apache daemon
apachectl stop
OR
apache2ctl stopRestarts the Apache daemon by sending it a SIGHUP
apachectl restart
OR
apache2ctl restartShows a full status report from mod_status
apachectl fullstatus
OR
apache2ctl fullstatusDisplays a brief status report
apachectl status
OR
apache2ctl statusGracefully restarts the Apache daemon by sending it a SIGUSR1
apachectl graceful
OR
apache2ctl gracefulWe can do gracefully stops the Apache httpd daemon too:
apachectl graceful-stop
OR
apache2ctl graceful-stopRun a configuration file syntax test
apachectl configtest
OR
apache2ctl configtestSumming up
You learned how to start, stop or restart the Apache 2 web server using command-line over ssh-based session. Use the man command to read the following man pages:
man service
man systemctl
man httpd
man apachectl
Comments
Post a Comment