Learn how to restart Apache webserver in Linux from the command line. Know log file locations to look for troubleshooting during the restart process.
Apache webserver is one of the most widely used web servers for the Linux environment. Its easy webserver configuration, quick SSL configuration, separated log files make it easy to manage for sysadmin.
In this post, we will be seeing how to restart apache instances in Linux from the command line. We will also see its log files which can help us while troubleshooting the restart process.
Apache instance normally resides in /etc/httpd
directory. If you have multiple instances running on the same machine then they might be in different directories under /etc/httpd/httpd-Name1
, /etc/httpd/httpd-Name2
etc. It is recommended to have different user ids to run different instances so that they can be managed separately well.
Check running Apache:
Currently running Apache instance can be identified by using any of below commands :
root@kerneltalks # ps -ef |grep -i httpd
apache 15785 20667 0 07:50 ? 00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache 15786 20667 0 07:50 ? 00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache 15787 20667 0 07:50 ? 00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache 15788 20667 0 07:50 ? 00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache 15789 20667 0 07:50 ? 00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
apache 15790 20667 0 07:50 ? 00:00:02 /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -k start
Since my machine has multiple Apache instances running, you can see the same PPID for all processes. This will be PPID of main httpd
service.
root@kerneltalks # service httpd status httpd (pid 20667) is running...
To stop Apache :
To stop Apache we need to invoke Apache control script and provide it with the configuration file name (so that it knows which instance to stop in case of multiple instances).
# /usr/sbin/apachectl -f /etc/httpd/conf/httpd.conf -k stop
In the above example apachectl
is supplied with conf file location (-f
) and option (-k
) to stop. Once above command is executed, you will notice httpd
processes are no more visible in ps -ef
output.
In case of single instance only you can directly stop service to stop Apache.
# service httpd stop
Once apache is stopped you will also notice that /var/httpd/logs/access.log
also stops populating.
To start Apache:
To start it again you need to invoke apachectl
with start argument.
# /usr/sbin/apachectl -f /etc/httpd/conf/httpd.conf -k start
In case of single instance you can directly start service.
# service httpd start
Once Apache is started backup you will see httpd
processes in ps -ef
output. Also access.log
will start populating again.
If Apache is not starting up (after you made changes in configurations) then you need to check error.log file for reasons. It resides under /etc/httpd/logs
directory.
To restart Apache :
Above both operations can be combined with restart options. When invoked, it will stop the instance first and then start it again.
# /usr/sbin/apachectl -f /etc/httpd/conf/httpd.conf -k restart
# service httpd restart
Above both commands restart Apache instances.
Share Your Comments & Feedback: