How to Enable Piped Logging in Apache

Reading Time: 3 minutes

Apache by default logs data directly to log files. While this isn’t a bad thing, it is not your only option. Both Apache 1.x and Apache 2.x bring with them the option of enabling something called “Piped Logging”, though cPanel will only allow you to enable it for version 2.x.

Piped logging is extremely powerful when used correctly, and has far more flexibility than what we are using here. The way it is described here, we will be attempting to negate the memory-hungry Apache processes that creep up when a server is hosting very low traffic websites (less than 1 request per second) with traditional Apache log configurations.

The Symptom: Apache Processes Using a Large Amount of Memory.

You will see Apache using a large percent of the memory (MEM) when running a ‘top‘, such as what you see below (when sorted by memory use) and you’ll also note that the root Apache process has been running for a long time.

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 15733 root      15   0  554m 541m 5752 S  0.0 52.9 851:59.84 httpd
 17790 www       15   0  556m 544m 5408 S  0.0 53.1   0:02.77 httpd
 17616 www       16   0  555m 543m 5440 S  0.0 53.1   0:04.69 httpd
 18368 www       15   0  555m 543m 5396 S  0.0 53.1   0:01.05 httpd
 29924 www       16   0  555m 543m 5548 S  0.0 53.1   0:08.91 httpd
 18363 www       15   0  555m 542m 5352 S  0.0 53.0   0:00.55 httpd
 22294 www       15   0  554m 542m 5376 S  3.9 53.0   0:00.27 httpd
 22093 www       15   0  555m 541m 4556 S  0.0 52.9   0:00.33 httpd
 22232 www       15   0  554m 541m 4552 S  0.0 52.9   0:00.27 httpd

To see if traditional logging is enabled, check your Apache error log for messages that show Apache being restarted around every 2 hours:

[host - root]: grep Graceful /usr/local/apache/logs/error_log

You may see something like this.

 [Mon May 31 14:29:55 2010] [notice] Graceful restart requested, doing restart
 [Mon May 31 16:43:37 2010] [notice] Graceful restart requested, doing restart
 [Mon May 31 18:57:19 2010] [notice] Graceful restart requested, doing restart
 [Mon May 31 21:11:02 2010] [notice] Graceful restart requested, doing restart

The Repair

Enabling Piped logging in this way has a few different effects, but the one we are primarily concerned with is preventing Apache from initiating that graceful restart request every two hours.

Warning:
By following these directions your Apache configuration is rebuilt from the existing cPanel templates (the last distilled configuration), so you will lose anything that was not added or configured through cPanel/WHM. The directions below explain how to make a backup of the configuration before rebuilding it.

Prerequisites

Root Access:
You will need to have root access to the server in order to implement piped logging.

Software Requirements:
Cpanel Version: 11.25.0-R43471 or later
Apache Version 2 or later

You can check your versions with the following commands:

cPanel:

[host - root]: cat /usr/local/cpanel/version

Apache:

[host - root]:  /usr/local/apache/bin/httpd -v

Step #1: Make a Backup of the Apache Configuration

Login to the server via SSH or TTY and execute the following command.

[host:root]: cp /usr/local/apache/conf/httpd.conf{,.prepipedlogging}

Step #2: Enable Piped Logging in WHM

Log into WHM, and follow this sequence to the right place:

  • Service Configuration >> Apache Configuration >> Piped Log Configuration
  • Enable piped Apache logging, save it and let it rebuild the configuration.

Conclusion

After making any changes that involve your Apache configuration it is a very good idea to test all your hosted sites to make sure they still work. If it’s not practical to check all of your sites check as many different sites as you can.

You should see a difference in your memory use and your service stability nearly immediately, and it should be long term.

Join Us!

Contact us today at 1.800.580.4985 to speak to a knowledgeable Hosting Solutions Provider who can get you the info you need, to make an informed decision right away.

Too busy to talk? Click HERE to open a quick chat with us to find out more. Would you like the information in an email you can review at your leisure? Email us today to get solid advice on which product in our line up would best suit your needs.

We look forward to hearing from you!

Series Navigation<< Previous Article
Refer a friend and get hosting credit!