In this article, we’ve covered 17 tips of tuning Apache performance. It will help your website perform better.
Let’s get started.
1. Remove Unused Modules
Save memory over non-loading modules that you may not need, including though not restricted to mod_php, mod_ruby, mod_perl, etc.
2. Use mod_disk_cache instead of mod_mem_cache
mod_cache to use the disk based storage manager implemented by mod_disk_cache. mod_mem_cache will rarely serve the same page twice in the same Apache process, so the result is mod_mem_cache use high memory and gives little performance.
3. Configure mod_disk_cache with a flat hierarchy
For the best result, configure mod_disk_cache with a flat hierarchy and place cache on a separate physical disk also ensure that you are using CacheDirLength=2 and CacheDirLevels=1.
4. Setup appropriate Expires, Etag, and Cache-Control Headers
To experience the best cache benefits, you need to mention when a file or header gets expire.
5. Use Piped Logging instead of direct logging
Piped logging can be most powerful when used correctly and also it is flexible. Piped logging can easily rotate the log file as compare to direct logging. Direct logging needs to restart Apache in order to use the next log file.
6. Utilize mod_gzip/mod_deflate
mod_gzip/mod_deflate is the compression module. It compresses the website content that is sent to the client browser to reduce page load time. It generally will benefit all user experience.
7. Turn HostnameLookups Off
When HostnameLookups on that increases latency and slow down sites. It is the best idea to turn it off. The problem comes when you use the latter in the deny access like Deny from user.isp.com in .htaccess file. Apache will do a reverse DNS lookup. The result of that is the client will find that your site loads very slowly. The solution for that is using an IP address instead of the hostname in deny access.
8. Use Persistent Connections
Persistent connections also know as keep alive. Keep alive allows the same TCP connection instead of opening a new connection. To set keep alive use KeepAlive On with KeepAliveTimeout and KeepAliveRequests. KeepAliveTimeout is a number of seconds to wait for the next request from the client. KeepAliveRequest is the maximum number of requests to allow.
9. Allow symlinks
Options +FollowSymLinks -SymLinksIfOwnerMatch. Otherwise, apache will make a separate call on each filename to ensure it is not a symlink.
10. Avoid Wildcards in DirectoryIndex
Use a specific DirectoryIndex, i.e. index.html or index.php, not index.
11. Increase Swappiness
Swappiness is a primary factor that determines the overall functionality and performance. Swappiness is a kernel parameter that defines how much Linux kernel will copy RAM content to swap. The default parameter’s value set to 60 and it can set from 0 to 100 /proc/sys/vm/swappiness. As a result, it will try to load several files as possible into the memory cache for quicker access.
12. Increase Max Open Files
If you are handling high loads increase the number of allowed open files. On linux, to increase open file limit, first check the value # /proc/sys/fs/file-max. Next, increase it by # sysctl -w fs.file-max=500000. It will set temporary, for the persistent change add one line fs.file-max=500000 into # vi /etc/sysctl.conf file. The changes will reflect by logout and login again.
13. Setup Frontend proxy for images and stylesheets
Allow your main web servers to process the application while images and stylesheets are served from frontend webservers
14. Use mod_passenger for rails
For faster spawning of the new application, mod_passenger helps a lot. It shares memory and resources between processes and also it removes unnecessary process and monitor them.
15. Don’t use threaded mpm with mod_php
Look at using mod_itk, mod_php tends to segfault with threaded mpm.
16. Flush buffers early for pre render
It takes 200ms to 500ms for backend server to create site page. Flushing buffers early can speed up start render times and display of useful content. It allows the browser to start fetching components. A good place to do this is right after the HEAD section – so that the browser can start fetching other objects.
17. Use a Cache for frequently accessed data
Cache can be used for storing less frequent data and sessions. It will speed up your apache render time as databases are slow.
To ensure that the performance has improved or load reduced is to use these techniques to hook up apache monitoring to Monitis hosted monitoring.
In this article we have seen 17 tips of tuning Apache performance.
[Need assistance to fix this error or install tools? We’ll help you.]