Skip to main content

Admin 101: Apache survival basics

Here's a quick Apache administration rundown for when you get thrown an Apache server to suddenly maintain at work.
Image
knife and compass on a stump

Pixabay.com

During my time as a support engineer, as well as in the military, I saw several occasions where a system administrator was given the task of administering a system that they were unfamiliar with. It always went something like this: "The guy who used to own this system took another job and so they gave it to me until they find a replacement." I had this conversation more times than I could count when it came to storage systems, and unsurprisingly enough, web servers as well.

Imagine you are thrown into a situation like this. Your company's Apache admin takes another job, gets fired, etc. Your manager comes to you and says that he needs you to run the system until they can get a replacement. So what do you do? Where do you go for answers? What do you need to know for basic operation? These are all great questions that we will answer together.

For starters, we need to know what role Apache plays in the environment. Apache is an open-source web server that allows us to host content online. If we are visiting a site, it checks our information and then connects us to the web pages and content that we request. In my personal experience, the product that I supported used Apache to host web-based graphical interfaces so that our customers could manage their storage systems remotely. It allowed them to perform maintenance, upgrades, patches, etc. Now that we have a basic understanding of what Apache is and why we need it, let’s look at basic administration.

Turning services on and off

The most basic piece of information you would want to know as an administrator is whether or not the service is up and running. For all services, there are three basic commands that you need to get an accurate snapshot of that service's status. You also need to enable services (Apache is one of those). In this article, all commands are run in a Red Hat Enterprise Linux 8 environment. 

To enable the Apache service we use the following command:

[root@rhel8dev ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

Note: This must be done before you can start or configure the service. 

Next, we will look at the status command:

[root@rhel8dev ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
Active: inactive (dead)
Docs: man:httpd.service(8)

You can see from the output above that the service is down. To change that status, we need to run the service start command shown here:

[root@rhel8dev ~]# systemctl start httpd

Note: There is no output for start and stop commands. 

Now, if we check the service's status with the command we saw previously, we can see that the service is up and running:

[root@rhel8dev ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
Active: active (running) since Mon 2019-10-07 12:25:18 EDT; 1min 25s ago
Docs: man:httpd.service(8)
Main PID: 3349 (httpd)
Status: "Running, listening on: port 80"
Tasks: 213 (limit: 18538)
Memory: 54.2M
CGroup: /system.slice/httpd.service
├─3349 /usr/sbin/httpd -DFOREGROUND
├─3350 /usr/sbin/httpd -DFOREGROUND
├─3351 /usr/sbin/httpd -DFOREGROUND
├─3352 /usr/sbin/httpd -DFOREGROUND
└─3353 /usr/sbin/httpd -DFOREGROUND

Oct 07 12:25:18 rhel8dev.test systemd[1]: Starting The Apache HTTP Server...
Oct 07 12:25:18 rhel8dev.test httpd[3349]: Server configured, listening on: port>
Oct 07 12:25:18 rhel8dev.test systemd[1]: Started The Apache HTTP Server.

To stop the service, use the following command:

[root@rhel8dev ~]# systemctl stop httpd

Again, you will see that there is no output associated with this command, so we need to use the status command to check that the "stop" was successful.

Open the firewall gates

As this is a web server, we need to make sure that the ports are open and listening for web traffic (HTTP and HTTPS). To enable these ports, we need to create a rule in the Linux firewall (as well as the company firewalls if applicable), as shown here:

[root@rhel8dev ~]# firewall-cmd --zone=public --permanent --add-service=http
success
[root@rhel8dev ~]# firewall-cmd --zone=public --permanent --add-service=https
success
[root@rhel8dev ~]# firewall-cmd --reload
success

Configuration and logs

Once you verify that everything is up and running, you may want (need) to change basic configuration settings. To do this, locate httpd.conf. By default, you will find it here:

[root@rhel8dev conf]# cd /etc/httpd/conf
[root@rhel8dev conf]# ls -lrt
total 28
-rw-r--r--. 1 root root 11899 Aug 29 11:15 httpd.conf
-rw-r--r--. 1 root root 13077 Aug 29 11:17 magic

Finally, when (not if) something goes wrong, you will want to know where to look to begin troubleshooting the issue. The two logs that you will want to view are error_log (which records all issues that occur and will sometimes generate a fix to be implemented) and access_log (which records all access request to the server and can also help in troubleshooting).  By default, both of these files are found here:

[root@rhel8dev logs]# cd /etc/httpd/logs
[root@rhel8dev logs]# ls -lrt
total 4
-rw-r--r--. 1 root root 0 Oct 7 12:25 access_log
-rw-r--r--. 1 root root 1002 Oct 7 12:27 error_log

Additional resources

Hopefully, you will never find yourself in this situation. However, if you do, now you have the building blocks needed to get started with Apache administration. For more information (which you will need), please visit the official Apache documentation site here.

Topics:   Linux   Networking  
Author’s photo

Tyler Carrigan

Tyler is a Community Manager at EnableSysAdmin, Submarine Veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a RHEL based combat system inside the USS Georgia Missile Control Center. More about me

Related Content

OUR BEST CONTENT, DELIVERED TO YOUR INBOX