enable gzip compression on apache server

How to enable GZip compression on Apache Server?

How to enable GZip compression on Apache Server

How to enable GZip compression on Apache Server

GZip compression is used to increase speed of web page in your site. Your browser send request to server and get all the images, javascript and css files from server. When your web page have lots of images, javascript and css files than its take time to load. GZip compression gives boost to your website speed and save bandwidth as well.
In a very simple language, GZip compress all the data and send to browser. All the latest browser understands and accept compressed files.
There are two major ways to enable the GZip Compression on the Apache Server web-sites.

1) Using httpd

You need to install mod_deflate module, if it is not installed than you can download it from Apache httpd Modules and add it to httpd modules directory on your server.

Once you add mod_deflate module in your httpd modules directory, you completed half work. Now open your “httpd.conf” file and search for “mod_deflate”. You will find the following line

LoadModule deflate_module modules/mod_deflate.so

If it is commented than uncomment it, so it will LoadModule directive for mod_deflate.

Now we need to create a Deflate Rule Set which tells your apache server that compress which types of file.

Create “httpd-deflate.conf” file and copy following code in that file

#Set GZip for all output
SetOutputFilter DEFLATE
#Not Include the below file types
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|iso|tar|bz2|sit|rar|png|jpg|gif|jpeg|flv|swf|mp3)$ no-gzip 
#Use compression Level
DeflateCompressionLevel 9
#You can Handle browser specific compression using following rules
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

Now, open “httpd.conf” file and add following code

# Deflate configuration
include <path of file>/httpd-deflate.conf

Now restart your Apache Server and its working GZip Compression. Your website will load 60% faster than before.

2) Using .htaccess file

You can add following code in your htaccess file

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

If above code is not working than you can try another code which is as below

<ifModule mod_gzip.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

MP4 404 file not found, even the file is already exist on location


are you facing MP4 404 file not found issue, even the file is already exist on location?

Recently, I am working with one of my project, where i called one MP4 vedio file in flash. basically its a webpage with the flash movie clips and then flash calling the .MP4 vedio file. when its not loading in flash file then i see that its give a 404 file or directory not found error in the http response. I check the path and its perfact, i mean there is a file on the same location, I thought that might be the file is currupt, so i replaced that file but not any improvement and its show me same 404 File not found error.

As its working fine in my local server but not working on the production server. I think that its a directory permissions issue because we do not want to set the permission in local server. I checked the file and folder permission and its configured correctly. Then i start to look on the server configuration and found that, Same web page is working on local server because it is apache server but its not working on the production server because its IIS server. And IIS threw 404 File not found error even if i open directly in browser. So this issue on an IIS server or we can say that its a IIS specific issue.

Now, i try something specific to .MP4 format and knew that .MP4 extension is not a native MIME Type in all windows server, which will be any version of IIS server. we need to add this extension manually in IIS server. I fixed it after adding this extension in the IIS, you can add any other extension which is not supported using the same way. To add the extension follow the below steps.

1) Open IIS Manager
2) Select your server and from the Features View open MIME Types
3) There is a add option at the right side, click on it
4) There is a File name extension: field, add the extension name which you want to add.
5) Next filed is MIME type: field, this is depends on the extension, so add it as per your extension.

Note : In my case File name extension is .MP4 and MIME Type is video/mp4.

Thats it, you did it.

Fatal error: Maximum execution time of 60 seconds exceeded in filename

Fetal error is one of the major issue in the php and all php programmer facing lots of issue day by day in php language.  some time you get Fatal error: Maximum execution time of 30 seconds exceeded in filename, basically this is the server issue, on the Apache server there is a number of seconds set to run the script, once that second finished and still not finish the execution of your php statements then you get this error.

On the server the default limit is 30 seconds, and you can find this in the php.ini file where you search the keyword ‘max_execution_time’ then you get the value set beside it. you can directly reset it in the php.ini file and it will apply on all the files. while if you want to set in any php file then you can set it using below statement.

1) set_time_limit(120);

2) set_time_limit(0);

When above statement called in your php file then  set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 120 seconds into script execution a call such as set_time_limit(120) is made, the script will run for a total of 120+30 seconds before timing out.

When you set set_time_limit(0) then its run for unlimited time, i mean its do not stop execution up to the end of your file.

PHP Fatal error: Allowed memory size of 8388608 bytes exhausted….(Resolved)

When you are working with the file upload,read file or write file then you get the issue regarding the memory size, its give you fetal error in php which is starting with below text.

PHP Fatal error: Allowed memory size of

This is not the programming error but you face this error because of server configuration, by default server allowed less memory because of better performance of server and server do not hang over. you can set the memory size using 3 ways. you can use any one from below 3 points.

1) ini_set(“memory_limit”,”64M”) : Here 64M indicate that you want to allowed up to 64MB. you can set it as per your requirement. once you set this then please put this code in the starting of your php file.

2) memory_limit = 64M : Here 64M indicate that you want to allowed up to 64MB. you can set it as per your requirement. Please update this in the php.ini file.

3) php_value memory_limit 64M : Here 64M indicate that you want to allowed up to 64MB. you can set it as per your requirement. Please place this code in your .htaccess file.

So, you can use it as per your convenience, if you want it for all files then you can change in .htaccess file, if you want on the server then you can change it in the php.ini file and if you need this configuration for particular file then you can use first option and place in your php file.

how to stop directory listing in apache web server

when you are working with the Apache server,  might be you place upload folder to upload the images and files in that, also some time you did not create index.html, index.htm or index.php file in the folder. some time you use any directory to transfer the files. now if above is the case then when you try using the link below then you see the result which is show below it.


Result show like list of all the directory inside that directory, in the given example importantfiles is the folder and there is 3 other folder named 4.0_r3, current and project in that folder.

As a security reason this is not good and you need to prevent it. i can help you how to prevent directory listing on apache server.

You need to create .htaccess file and need to write below code in that htaccess file. once its done then upload that file in the root directory or the directory in which you want to stop directory listing. if you put it in root directory then its stop directory listing for root directory and all the sub-directory inside that directory.

Options -Indexes

When you did this then if there is no index file then its give you result like below:


You don’t have permission to access /uploads/ on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/ Server at ilibya.com Port 80

This is the 403 error and if you get this error then you want to redirect on any custom created page or template then use below line in the .htaccess file.

ErrorDocument 403 /index.php

You can set your own file name where i put the index.php, using above rule you can redirect on custom template.

How to redirect on index page or the home page when 403 error or 404  error found on the Apache server.

if you get error 403 or error 404 and you want to redirect user on home page or any particular custom page then please write below code in your .htaccess file.

ErrorDocument 403 http://www.yourdomain.com
ErrorDocument 404 http://www.yourdomain.com

Now you can stop the directory listing in your web-site.