Activating Certain Features On Installation

markb14391

Well-Known Member
Jun 9, 2008
305
2
68
Hi,

It is possible to configure certain cPanel features to be activated on account creation? For example, I'd like for compression ("Website Optimization") to be on by default.

Thanks,

Mark
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
Hello Mark,

If you place the following content into /root/cpanel3-skel location with a file you name .htaccess, then you will have Optimize Website enabled for "Compress all content" radio button:

Code:
<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        
        # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        
        # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        
        # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
        
        # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>
    
    <IfModule mod_headers.c>
        # Make sure proxies don't deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>
For this code, place it into an .htaccess file (again, at /root/cpanel3-skel/ location) and then try creating a new account. You will see that /home/username/.htaccess has the above content and then when you visit cPanel > Optimize Website for that new account, you will see the radio button for "Compress all content" already selected.

Thanks!
 

markb14391

Well-Known Member
Jun 9, 2008
305
2
68
Thank you so much! That's easy!

Followup question (somewhat related):

We'd also like to activate browser caching by default on our WordPress hosting plans (a cPanel account with WordPress preinstalled). So, in addition to the code you mentioned for compression, can we just add that code to our created .htaccess file in the skeleton?

For example:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##

Thanks,

Mark
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
You can add whatever entries you would like into the .htaccess in /root/cpanel3-skel location. Anything placed there will be copied into the new account during creation.
 

markb14391

Well-Known Member
Jun 9, 2008
305
2
68
Followup: What if users install new web sites within their accounts (e.g., installing WordPress with Installatron in a subdirectory)...will those new sites have any of these features too? For example, is the "Optimize Website" function inherited?

Thanks and best regards,

Mark
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
This code is only added during main account creation. If you want anything added during any subdomain or addon creation, you'll need to create a hook script to tie into that creation process. I'd suggest posting that question into the developers section of the forum.