Introduction
Apache is a popular open-source web server used to host websites and applications. It is widely used in Linux-based operating systems, such as CentOS 7. In this tutorial, we will show you how to start, stop, and restart Apache server on CentOS 7. We will also provide some useful tips and tricks to help you manage your Apache server more efficiently.
How to Start, Stop, or Restart Apache Server on CentOS 7
1. To start Apache server on CentOS 7, open a terminal window and type:
sudo systemctl start httpd.service
2. To stop Apache server on CentOS 7, open a terminal window and type:
sudo systemctl stop httpd.service
3. To restart Apache server on CentOS 7, open a terminal window and type:
sudo systemctl restart httpd.service
Introduction
Apache is part of the popular LAMP (Linux, Apache, MySQL, PHP) stack of software. It’s responsible for the function of most of the internet.
This guide will show you how to restart Apache service on Linux CentOS 7.
Prerequisites
- Access to a user account with sudo privileges
- An installed and configured Apache installation
- Access to a command line / terminal window (Menu > Applications > Utilities > Terminal)
Restarting Apache on CentOS 7
Method 1: Restart Apache Server Using Systemctl Command
Open a terminal window and enter the following:
sudo systemctl restart httpd.service
The service should restart.
The restart command can take several moments to complete, depending on the complexity of your server configuration. If you’re running a large or complex server configuration, this can cause disruptions for users who rely on the server.
Method 2: Restart HTTPD Server Using Apachectl Command Script
Apache recommends using a control script to pass commands to the httpd process.
To restart Apache in this manner, enter the following:
sudo apachectl -k restart
To instruct the Apache service to terminate all child processes and itself, run the following command:
apachectl -k stop
Use the below-mentioned command to exit child processes after they finish a task and then launch new instances. The service will reload configuration files as well.
apachectl -k graceful
Use -k restart
to force child processes to exit. The parent process stays running, and reloads configuration files.
apachectl -k restart
Use -k graceful-stop
to force parent process to stop child processes as they complete their tasks. Once all child processes are stopped, the parent process exits.
apachectl -k graceful–stop
For more information on the apachectl
command, see the Apache documentation.
Other Commands to Use with Systemctl
To start the Apache service:
sudo systemctl start httpd.service
Stop the Apache service with:
sudo systemctl stop httpd.service
Force Apache to refresh the configuration files:
sudo systemctl reload httpd.service
Set Apache to run when the system boots:
sudo systemctl enable httpd.service
Prevent Apache from loading when the system boots:
sudo systemctl disable httpd.service
The reload
command is faster and creates much less disruption than restart. However, this only performs a soft refresh of the configuration files. Some services and dependencies may not be included in the refresh.
One good practice is to weigh the benefits against the costs of each process. If you have several clients depending on access to your server, try to refresh first. If that doesn’t work, or if the disruption is minimal, use restart.
Apache Best Practices
Like many Linux services, Apache’s functionality can be modified using configuration files and modules. Configuration files should all be stored in the /etc/httpd/ directory.
In that directory, look for the /httpd.conf file – this is the main configuration file for Apache’s global settings. You can edit this file with any text editor to change your Apache configuration.
Apache’s functionality can be enhanced using modules. A module is an application that works in conjunction with the main Apache application. For example, the mod_bandwidth module allows you to set a bandwidth limit on each connection.
Available modules can be found in the /etc/httpd/mods-available directory.
Use the following commands to manage modules:
sudo a2enconf mod_name
To disable a module:
sudo a2disconf mod_name
You can configure Apache to listen on specific ports by editing the /etc/apache2/ports.conf file.
Apache creates log files during usage. The error log reports any problems, misconfigurations, or other issues. You can use the error log to find issues with your configuration.
The access log tracks every client that connects to your Apache server. This can be used to view resources being used or how users interact with your website.
Apache access and error log files can grow large as they record so much data. Most users will use a tool like tail or cat to display a portion of the log file.
As Apache runs, the log files will use more disk space. To keep them manageable, Apache recommends rotating log files and using the graceful restart option above.
Apache can manage multiple websites, called virtual hosts, on the same system. Content is stored in the /var/www/ directory.
Available sites are stored in /etc/httpd/sites-available , and enabled sites are stored in /etc/httpd/sites-enabled.
Conclusion
Starting, stopping, & restarting the Apache service is relatively straightforward. You can use additional commands to customize your particular configuration.
For example, you might choose to reload Apache instead of a full restart. Or, you might use the apachectl
command for more control over your server.
How to Start, Stop, or Restart Apache Server on CentOS 7
Apache is an open-source web server that is used to serve web pages to users on the internet. It is one of the most popular web servers in the world, and is used by many websites and applications. If you are running a CentOS 7 server, you may need to start, stop, or restart the Apache web server at some point. This guide will show you how to do this.
Prerequisites
Before you begin, you will need to have access to a CentOS 7 server with Apache installed. You will also need to have root access to the server.
Starting Apache
To start the Apache web server, you can use the systemctl command. This command will start the Apache service and enable it to start on boot:
sudo systemctl start httpd sudo systemctl enable httpd
Once the command has been executed, you can check the status of the Apache service to make sure it is running:
sudo systemctl status httpd
Stopping Apache
To stop the Apache web server, you can use the systemctl command. This command will stop the Apache service and disable it from starting on boot:
sudo systemctl stop httpd sudo systemctl disable httpd
Once the command has been executed, you can check the status of the Apache service to make sure it is stopped:
sudo systemctl status httpd
Restarting Apache
To restart the Apache web server, you can use the systemctl command. This command will restart the Apache service and keep it enabled to start on boot:
sudo systemctl restart httpd
Once the command has been executed, you can check the status of the Apache service to make sure it is running:
sudo systemctl status httpd
Conclusion
In this guide, we have shown you how to start, stop, and restart the Apache web server on CentOS 7. We have also shown you how to check the status of the Apache service. Now that you know how to manage the Apache web server, you can use it to serve web pages to users on the internet.