
Apache is one of the most popular web servers today. For a long time, it was utterly dominant over the alternatives, but NGINX is now around the same popularity. However, given that so many people use NGINX as a reverse proxy for an Apache backend server, it’s likely that Apache still maintains a solid lead compared to its rivals like NGINX, LiteSpeed, and others.
Given its popularity, chances are that you’re running an Apache server yourself on your VPS. And it’s important to know how to restart Apache both gracefully and otherwise, as well as the reasons to do so. This article will explain both, along with all the other implications of restarting Apache.
How to Restart Apache
There are two ways to restart Apache – gracefully, and a “hard” restart. Here’s how to do both.
Gracefully Restart Apache
A “graceful” restart is where you restart the Apache server without dropping active connections. This is used when the configuration changes to Apache are minimal, and you want to restart it without impacting the existing users that are connected. A graceful restart has minimal interruption to server activity since new worker processes are loaded with the new configuration while the older ones continue to finish their work with the older configuration. Changes to modules or their parameters might not necessitate a complete cessation of connections, so this is the preferred mode whenever possible.
Here are the commands to gracefully restart Apache:
For modern systems supporting the systemd framework like Ubuntu and CentOS, you can gracefully restart Apache using the following commands:
For Ubuntu systems:
sudo systemctl reload apache2
For CentOS systems:
sudo systemctl reload httpd
For older systems not supporting systemd, you can use:
sudo apachectl graceful
or
sudo httpd -k graceful
Hard Restarting Apache
While you should gracefully restart Apache whenever possible, there are many situations where you need to hard restart it, instead. Here are some possible reasons:
Changes to httpd.conf or apache2.conf:
These configuration files are key to Apache, and if you’ve made significant changes to them, then you should hard restart them to ensure consistency.
Module changes:
While it’s possible to avoid a hard restart with certain modules, for others, there’s no escaping the need for a whole new process.
Performance Issues:
Sometimes, when Apache has been running for too long, it can suffer from performance issues due to memory leaks, or other situations where it starts to use up too many resources. In such situations, a hard reset is your only option.
Instability:
When Apache is behaving erratically, or it stops responding, or crashes, then you have no choice but to force a hard reset.
Updates to SSL Certificates:
Often, SSL certificates are deeply integrated into Apache’s configuration and when they change, it’s best to start fresh.
For these and other situations, you should always issue a hard restart. Here’s how to do it for systems that support the systemd architecture:
For Ubuntu systems:
sudo systemctl restart apache2
And for CentOS systems:
sudo systemctl restart httpd
Note that the difference between the commands for a graceful and a hard restart is that one uses “reload”, and the other uses “restart”.
Folder systems:
sudo apachectl restart
or
sudo httpd -k restart
Common Issues When Restarting Apache
Restarting Apache should be a relatively straightforward affair. However, sometimes things go wrong. Here are the possible errors you can encounter.
Syntax Errors in Configuration Files
If you have an error in the configuration files related to Apache, it’s not going to start up. This is a good reason why you should always take a backup of config files before you make any changes. If Apache was working before and isn’t working now, you can revert to the old configuration file and see if it works. If so, then you know the problem resides in a syntax error.
Incorrect Permissions
Apache requires a specific set of permissions to run properly. For example, files and directories need to be owned by the group to which the Apache user belongs. This user is either “apache”, or “www-data”.
Configuration Files
For my installation, the Apache configuration file is located at:
/etc/apache2/conf/httpd.conf
The above file needs to be readable by the root user and the Apache user.
Web Content
This is the content that you want the Apache server to return. As a result, you need to ensure that it’s readable by Apache.
Log Files
Since Apache needs to modify these files, you should ensure that it has write access to log files.
Permission issues when starting Apache can be frustrating to debug, so make sure you check all the other possible issues before focusing on permission.
Port Conflicts
Apache usually runs on port 80 and 443, depending on whether or not it services HTTP requests. If another service is using either of these ports, Apache won’t be able to start.
Resource Limits
Every VPS has its limits, and if Apache uses up more than what’s allowed, it can fail to start. Memory limits, network limits, process, and user limits can all contribute to excessive resource usage.
However, Apache itself also has limits beyond what the VPS or dedicated server allows. For example, there is a parameter called “MaxRequestWorkers” that’s set in the configuration file that defines how many simultaneous requests Apache will serve. Here’s how it’s typically defined:
<IfModule mpm_prefork_module>
MaxRequestWorkers 150
</IfModule>
<IfModule mpm_worker_module>
MaxRequestWorkers 150
</IfModule>
As you can see, by default, Apache can serve up to 150 simultaneous requests. This can be modified by the server administrator, but it puts a hard cap on what Apache can do. Other restrictions include server limits, thread limits, limits on the number of threads each child process can create, and more. Several of these depend on the underlying server resources, so they’re not completely divorced from the VPS itself.
Apache Server Logs to Check for Errors on Failed Restarts
If Apache fails to restart, you must first look at the Apache logs to try and see if there’s a helpful error message to guide you. Unfortunately, there’s no standard location for Apache error logs. On my system, the location is:
/etc/apache2/logs
But the “logs” folder above is a symbolic link and the actual logs are located at:
/var/log/apache2
Depending on your Linux distribution, the version of Apache, and even how Apache was installed, the log files can be located in different directories. You can customize the location of these log files using the “ErrorLog” directive in Apache as follows:
ErrorLog ${APACHE_LOG_DIR}/error.log
However, the ErrorLog directive only exists when you manually want to change the default error log location. Without this, the default compiled-in location is used. To find out what that is, you can use the following command:
httpd -V | grep SERVER_CONFIG_FILE
This will give an output like this:
The trick is to use the command without “sudo” so that Linux throws an error and you can see the full location of the log file!
Conclusion
As you can see, restarting Apache is quite a simple matter. You can either gracefully restart it, or go for a hard restart. Truth is, both can be quite fast and unless you have a specific reason to restart Apache gracefully, it’s more thorough to make it a hard restart. If Apache fails to restart, you can check the error logs to discover what happened.

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
Leave a Reply