- A Cloud Guru
Troubleshooting an Apache Installation
Understanding a service well enough to troubleshoot it is an important skill as a System Administrator. In this lab, we'll go over troubleshooting an Apache installation.
Table of Contents
Ensure Apache starts correctly.
The first thing to check is why Apache isn't starting in the first place.
systemctl start httpd
Failed to start httpd.service: Unit not found.
It looks like the junior admin didn't think to install Apache. Let's install it:
yum install httpd -y systemctl start httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
systemctl status httpd -l, we see errors like:
Apr 20 16:20:10 server1 httpd: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
So something is already running on port 80. Running
ss -lpshows us that
nginxis running and listening on port 80 and port 443. We need to stop
systemctl stop nginx systemctl start httpd
Finally, Apache is running.
Ensure files are being served correctly.
If everything is configured properly, simply running
curl localhostshould get our webpage.
It doesn't, unfortunately. Now we need to configure Apache to use the different DocumentRoot we're using here. We need to edit
/etc/httpd/conf/httpd.confand replace all instances of
/opt/website/. We also need to make sure SSL is enabled. First, we need to install the
yum install mod_ssl -y
Fortunately, there's a sample configuration file in the
/rootdirectory. Copy that to
/etc/httpd/conf.d/, and we should be good to go after restarting Apache:
systemctl restart httpd curl https://localhost -k
-kis used to ignore alerts due to a self-signed certificate)
The result doesn't look like our index.html (you can
cat /opt/website/index.htmlto verify).
/var/log/httpd/error_log, it looks like a permission issue. Using just
ls -l /opt/website, everything looks fine - but maybe it's SELinux. Check with:
# ls -lZ /opt/website/ -rw-r--r--. root root system_u:object_r:admin_home_t:s0 index.html drwxr-xr-x. root root system_u:object_r:admin_home_t:s0 storage
admin_home_tis for admin home files (like
root's home directory) Compare that to the default
# ls -lZ /var/www drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html
So all we need to do is:
chcon -R system_u:object_r:httpd_sys_content_t:s0 /opt/website/*
curlshould work fine. Good job!
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.