Apache is a free and open-source cross-platform web server software. It is one of the most popular HTTP servers. Generally, it is used in combination with MySQL, PHP, and other scripting languages and forms a robust platform for the deployment of web applications.
Apache package on CentOS and Red Hat Linux is available with the name httpd. As I already discussed how to set up the apache web server on CentOS.
In this article, we will discuss different methods of how to start, stop and restart the apache server on CentOS or Red Hat Linux.
Prerequisites
To manage apache services on CentOS or RHEL you should have the following.
- CentOS/ RHEL running with the apache web server installed on it
- A user account with superuser privileges
Start, stop and restart the apache using the systemctl command
Most of the modern distributions today uses systemd as init system. On these systems, we can use the systemctl command to manage services. Now see the given commands that can be used on CentOS / RHEL to manage apache services.
Use the following command to start the apache web server on your system –
sudo systemctl start httpd
You can check the status, if the server is running properly or not by using –
sudo systemctl status httpd
Generally, you need to restart or reload your server after making changes in the configuration file. You can use the following command to restart the apache server on your system –
sudo systemctl restart httpd
You can also use the reload command to refresh the configuration files of the apache server. This command is faster and creates less disruption to the webserver –
sudo systemctl reload httpd
If you want to stop the server then use –
sudo systemctl stop httpd
Start, stop and restart the apache webserver using the apachectl command script
Starting httpd using the apachectl
control script sets the environmental variables in /etc/sysconfig/httpd
and starts httpd. The environment variable can also be set using init script.
Apache recommends to use control scripts to pass the command to httpd processes. The apachectl commands are given below.
To start apache server use –
sudo apachectl start
You can check the status, if your server is running properly or not by using –
sudo apachectl status
To restart the apache services use –
sudo apachectl restart
If you want to stop the server then you can do this by using –
sudo apachectl stop
Conclusion
Now you know how to manage apache services on a CentOS or RHEL server. If you have any other query then write us in the comments below.