Optimize Apache for Better Performance and Reduce RAM Usage

Apache has great features, strong development and support base, but the problem with Apache is consuming of memory, it will consume the entire server RAM like a beast, this is really a frustrating situation for any webmaster because upgrading the RAM on a VPS or dedicated server isn’t so cheap. We have observed this situation with lot of our customers, so we thought lets give them some great tips to minimize the RAM usage of Apache.

Do you know Hostocol offers fully managed Linux VPS hosting with free cPanel?

There are two possible solutions for this problem, one by tweaking Apache and reducing RAM usage. Second, simply switch to Nginx, which consumes really a very low memory and the performance level is really astonishing compared to Apache. We did a lot of load testing etc and finally agree that Nginx is way better in terms of performance and handling multiple concurrent connections at a time. We will write a complete comparison report and review on Apache and Nginx in our upcoming articles.

Apache Speed

Tip to Optimize Apache and Reducing RAM usage:

Apache has a special feature called Multiprocessing Module (MPMs), which helps it in handling the multiprocessing of threads, which obviously increase your server load by running spare servers unnecessarily, this will easily suck up all your RAM memory.

Note: Please apply these settings at your own risk, we do not hold any responsibility if something goes wrong, also don’t try this on a production server directly.

Steps to Optimize Apache:

1) Open your Apache configuration file which is normally located at..


2) Go to the below location where you can find this code..

<IfModule prefork.c>
StartServers       8
MinSpareServers    1
MaxSpareServers    10
ServerLimit        50
MaxClients        50
MaxRequestsPerChild  4000

For your understand here is what every term means..

# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves

3) Just reduce the number of server start to lower number, in my case I set it as “1″. Also set the minimum spare server value to “1″. Set Max Spare server value to 4 or 5, server limit to 50 or 60 (test with different values).

4) Just below to the prefork settings, you can see worker settings as well, worker can better your website performance if you optimize it correctly. It will look like this..

<IfModule worker.c>
StartServers       8
MaxClients        50
MinSpareThreads    5
MaxSpareThreads    4
ThreadsPerChild     25
MaxRequestsPerChild  0

You can actually change the values according to your convenient, also check out what those terms mean by…

# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves

5) This will almost do the job, but as we said work a little on your enabled modules which unnecessarily lying in your configuration and wasting the server resources. Please do check before you disable any module and what is its functionality first, then you can go ahead with the disabling.

6) Remove unnecessary packages lying in your servers which runs in background and sucks all your memory without your knowledge. Disable unnecessary background running processes as well.

7) Another simple way to optimize your website performance is by installing the mod_pagespeed module, this can also help in optimizing your website performance dramatically.

Please try experimenting with different values in prefork and worker configurations, just see which can improve your website performance and reduce the RAM usage as well.

If you enjoyed this article, please don’t forget to share it with others. Also do drop your comments, suggestions and questions in the below section.

Set 301 Redirection from non-www to WWW Domain

In our previous article we explained on how to set redirection from WWW to non-www based domain, today lets learn how to set redirection from non-WWW to WWW domain. Choosing one standard form for your URL structure is very important, this will help in terms of SEO and let search engines not consider your content as duplicate.

To set 301 redirection from non www to www domain, follow the below instructions..

non www to www:

  1. Open your htaccesss file, if it is not there in your domain root directory, simply create it using the notepad from your desktop and name it as .htaccess.
  2. Now paste the below piece of code in your htaccess.
  3. RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

  4. Please replace yourdomain.com with your own domain name. Also make sure that your website does support Mod-rewrite and your web server should be Apache.

I hope learned on how to set 301 redirect non www domain to www domain, please do drop your precious comments and questions.

Set Redirection from WWW to Non-WWW Website

This article helps you setting up a redirection from WWW to non-WWW domain, this is very essential for SEO purposes and avoid duplicate content issues, major search engines like Google, Bing and Yahoo assumes WWW and non-WWW based domains as separate.

So it is very essential to set proper redirections for search engine’s understanding.

WWW to non-WWW:

  1. Open your htaccesss file, if it is not there in your domain root directory, simply create it using the notepad from your desktop and name it as .htaccess.
  2. After creating the htaccess, now please paste the below code in the htaccess file.
  3. RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC] RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

  4. In above code, don’t forget to replace yourdomain.com with your own domain name. Also please make sure that your website does support Mod-rewrite and your web server should be Apache.

The above code will redirect your www based domain to non-www based domain. Hope this article helped your question, also please consider sharing with others.

Failed to Write File to Disk Error while Uploading Images in WordPress

This is a common error occurs in some web hosting environments, if you are a WordPress lover then probably you might experience this in your journey, if you encounter “failed to write file to disk error” just don’t panic it has a simple fix. Follow the below procedure to fix the failed to write file to disk problem…

There are several reasons which could cause this problem, we mentioned them and given all possible fix for this issue.

WordPress Failed to Write File to Disk Error Fix

Failed to Write File to Disk Error Fix:

  1. This error may cause if your images folder or the parent folder is not writable, to fix this you have to give 755 or 777 permissions using your favorite FTP client.
  2. This can also occur in case if your disk quota is full, please check with your web hosting provider to fix this problem.
  3. This issue can also happen in case if your temporary folder of the server is full, because of which WordPress cannot able to upload the image through it. To fix this issue, contact your web hosting support and ask them to clear the temporary files in the server directory. To fix this permanently ask your support to WordPress temporary path to a local one, that should fix the issue.

The above three cases might cause this problem, we hope this should fix your problem. Please drop your questions, comments and suggestions in the comments section below.

How to Create and Edit “A” Records in DNS Editor of cPanel?

If you want to point a sub-domain or a domain to a particular IP address then you may have to use “A” records. Follow the below procedure to point “A” name records using cPanel.

Create “A” Record using cPanel:

  1. Login to your cPanel control panel, you can found the URL from your welcome email or simply login to the billing panel (https://my.hostocol.in/), then go to the .
  2. Once log in to your cPanel account, click on “Simple DNS Zone editor”. See the below screenshot. Simple DNS Zone Editor
  3. In the name section, type the sub domain name “only name not total URL”.
  4. In the Address section enter the IP address of the server or website you would like to point.
  5. Now click on Add a record.
  6. That’s all.

This is how you should add an “A” record using the cPanel, please do drop your comments and questions in the comments section.

Renew your Domain Name

How to renew a domain name?

Renewing your domain is a simple process with Hostocol, extend your domain years by simply renewing them. To renew your existing domain with Hostocol please follow this below procedure…

Domain Renew Procedure:

1) Login to the billing panel at https://my.hostocol.in

2) Now, go to Domains section in the Menu, then click on the “Renew Domains” section.

3) You can able to see the existing domain names which are available for the renewal.

4) Click on “Renew” and fill out the billing details and you are done.

You can also set “Auto Renew” by storing your credit card details and however all the new domains purchased set for Auto Renewal by default. If you want to disable you can do this in the same billing panel.

Let us know if you face any issues while renewing your domain names.