meldroz

Registered
May 31, 2012
1
0
51
cPanel Access Level
Root Administrator
Hello,

I'm new to Cpanel and server administration in general. I need to enable client caching because of i have a lot of static images that i will probably never change. I looked online and there seem to be different way of doing this.
I'm running cpanel and easyapache install.

Thank you,

Mel
 

Chris.Bshm

Member
Oct 20, 2011
13
0
51
Hello,

It seems you may be wanting to discuss server side caching for Apache. These options would include eAccelerator, XCache, etc. There are a few downsides with installing these, ex:

eAccelerator:
Generates cached files in /tmp - depending on the size of your /tmp directory this can become full causing services like MySQL to fail.
Additional CPU Usage to generate cache pages.

Also, eAccelerator is not compatible with PHP Handlers like SuPHP which is installed by default. This however can be changed in WHM >> Configure PHP & SuEXEC; additionally, eAccelerator can be installed via WHM >> EasyApache >> Exhaustive Options List

https://eaccelerator.net/
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
348
somewhere over the rainbow
cPanel Access Level
Root Administrator
No PHP OPCode caching options (eAccelerator, xCache, APC) work with suPHP, so it isn't just eAccelerator that doesn't function with it. DSO and FCGI do work with OPCode caching, but I don't understand the purpose of having OPCode caching for PHP if the main reason is to cache images? It only works for PHP and hasn't anything to do with image files (jpg, png, gif, etc.).
 

srpurdy

Well-Known Member
Jun 1, 2011
101
0
66
cPanel Access Level
Root Administrator
I think what you really want is a CDN of some sort. That will take load off your server, and serve static content for you from a global network. Browsers are configured by default to cache content. As long as you use good expire headers on files you should be okay. (you may want to compile in mod_headers and mod_expire into apache if you do want control over this.

you may also make sure compression is enabled for browsers that support compression so that the size of the site data is much smaller with gzip compression. I don't remember if this on by default or not in cpanel.. (you can install mod_deflate) for this.

I usually use rules like this in htaccess, although you can customize them for how you want.
Code:
# 1 YEAR
ExpiresActive On
<FilesMatch "\.(otf|ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
ExpiresDefault "access plus 1 years"
Header unset Last-Modified
Header unset ETag
SetOutputFilter DEFLATE
</FilesMatch>

# 1 MONTHS
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2419200, public"
ExpiresDefault "access plus 1 month"
SetOutputFilter DEFLATE
</FilesMatch>

<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=604800, public"
ExpiresDefault "access plus 1 week"
SetOutputFilter DEFLATE
</FilesMatch>

# 30 MIN
<FilesMatch "\.(html|htm|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
 
Last edited:

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
348
somewhere over the rainbow
cPanel Access Level
Root Administrator
mod_deflate isn't installed by default. Also, it isn't added after installing in EasyApache onto sites by default. You'd have to either add an .htaccess such as you are mentioning after adding mod_deflate or use cPanel > Website Optimization to add content to the /home/username/.htaccess we add for it.

Please note that when adding Website Optimization in cPanel, we place the mod_deflate compression lines into /home/username/.htaccess rather than /home/username/public_html/.htaccess. We do this because subdomains and addon domains aren't always placed into public_html since you can have them at /home/username/subdomainfolder and for mod_deflate to handle all sites under that scenario, the .htaccess has to be in the document root.