Featured post

Learn Basics of Computer

What is Computer ? Computer is an electronic data processing machine which accepts input data from the user, stores the input data in its memory, processes the input data according to given instructions and finally gives us the desired output. What are Data ? Data are the raw facts and figures in the form of bits and bytes. What is information ? Information is processed data. Components of Computer Computer has two components. Such as: Hardware Software What is Hardware ? All the parts of computer that we can see and touch are known as hardware. Example - Keyboard, Mouse, Monitor, etc. What is Software ? A set of statements written in a programming language is known as a instruction. A set of instructions is known as a program. A set of programs is known as a software. Example - Microsoft Windows, Adobe Photoshop, Typing Master, etc. Classification of Computers Computers can be classified into three categories. Those are: According to type of dat...

Start / Stop and Restart Apache 2 Web Server Command

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 levelEasy
Root privilegesYes
RequirementsApache 2 on Linux / Unix
Est. reading time4 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 server

Once 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 restart
OR
$ sudo /etc/init.d/apache2 restart
OR
$ sudo service apache2 restart

To stop Apache 2 web server, enter:



# /etc/init.d/apache2 stop
OR
$ sudo /etc/init.d/apache2 stop
OR
$ sudo service apache2 stop

To start Apache 2 web server, enter:



# /etc/init.d/apache2 start
OR
$ sudo /etc/init.d/apache2 start
OR
$ sudo service apache2 start

A 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.service

We 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 restart


CentOS/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.service

The 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 apache2ctl

Outputs 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.conf

The apachectl/apache2ctl is Apache HTTP server control interface. Other options are as follows:

Start the Apache daemon



apachectl start

OR



apache2ctl start


Stops the Apache daemon



apachectl stop

OR



apache2ctl stop


Restarts the Apache daemon by sending it a SIGHUP



apachectl restart

OR



apache2ctl restart


Shows a full status report from mod_status



apachectl fullstatus

OR



apache2ctl fullstatus


Displays a brief status report



apachectl status

OR



apache2ctl status


Gracefully restarts the Apache daemon by sending it a SIGUSR1



apachectl graceful

OR



apache2ctl graceful

We can do gracefully stops the Apache httpd daemon too:
apachectl graceful-stop

OR



apache2ctl graceful-stop


Run a configuration file syntax test



apachectl configtest

OR



apache2ctl configtest


Summing 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

Popular posts from this blog

CakePHP 3.10 Content Management Tutorial

How to Install Croogo CMS on Ubuntu 18.04 LTS

How to Build a Dedicated Web Server : 4 Steps