Install apache mod expires on Ubuntu 9.10 Karmic

By | May 27, 2010

Apache mod expires

mod expires is an Apache module that can send additional expiry information about a server file to a browser. If the expiry date is set to a far future date, then the browser will fetch the file from its cache on next request and will not contact the server. This will speed up the loading time of the website. mod expires is typically used for static files like javascript , css and images.

To enable mod expires on ubuntu karmic koala :

sudo a2enmod headers
sudo a2enmod expires
sudo /etc/init.d/apache2 restart

If you 500 Internal Server Error :

1.Check the apache error log :

$ cat /var/log/apache2/error.log

It might show the error message :

[Sun Nov 06 16:27:55 2011] [alert] [client] /var/www/.htaccess: ExpiresActive not allowed here

2. To fix the above error open up the apache configuration file :

$ gksudo gedit /etc/apache2/sites-available/default

Add Indexes to the AllowOverride line for /var/www/ :

<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride FileInfo Options Indexes
		Order allow,deny
		allow from all

Now the 500 Internal Server Error should be gone and mod expires should work fine.

To enable mod expires on a web directory put something like this in the htaccess file :

#Now set the expires time for various type of contents
<IfModule mod_expires.c>
	ExpiresActive On
	#30 days
	ExpiresByType image/x-icon A2592000
	ExpiresByType application/x-javascript A2592000
	ExpiresByType application/javascript A2592000
	ExpiresByType text/javascript A2592000
	ExpiresByType text/ecmascript A2592000
	ExpiresByType text/css A2592000
	#7 Days
	ExpiresByType image/gif A604800
	ExpiresByType image/png A604800
	ExpiresByType image/jpeg A604800
	ExpiresByType text/plain A604800
	ExpiresByType application/x-shockwave-flash A604800
	ExpiresByType video/x-flv A604800
	ExpiresByType application/pdf A604800
	#ExpiresByType text/html A900

This will enable mod expires far future dates for various content types like javacsript , css , images , flash videos etc. You can also check the performance with the YSlow plugin for Firefox.

Last Updated On : 27th May 2010

Leave a Reply

Your email address will not be published. Required fields are marked *