Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Migrated to EA4, mod_headers not working in .htaccess

Discussion in 'EasyApache' started by fonginator, Oct 19, 2016.

  1. fonginator

    fonginator Registered

    Joined:
    Oct 19, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    76
    Location:
    Montreal, Canada
    cPanel Access Level:
    Root Administrator
    Hi,

    I took the plunge and migrated to EasyApache 4 last night. Everything mostly went smoothly, but I am noticing now that my sites' HSTS headers (which are set in their respective .htaccess files) are no longer being sent.

    This is what used to work under my EasyApache 3 setup:

    <IfModule mod_headers.c>
    Header add Strict-Transport-Security "max-age=31536000"
    </IfModule>

    But no matter what I try (Header always add, Header set, Header always set...), this header never gets sent. Everything else in the .htaccess files seems to be getting parsed and I can trigger an HTTP 500 error if I create a syntax error in one of these files so I know they are being processed. Removing the <IfModule></IfModule> conditional doesn't help either, and I can confirm that mod_headers is activated in Apache.

    Any ideas how to resolve this problem?
     
  2. cPLevey

    cPLevey Technical Analyst Supervisor
    Staff Member

    Joined:
    Dec 3, 2015
    Messages:
    44
    Likes Received:
    8
    Trophy Points:
    83
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Welcome to EasyApache 4!

    Personally, I have HSTS headers configured on my EasyApache 4 setup, using Virtual Host Include Files. Documentation for this can be found here: Modify Apache Virtual Hosts with Include Files

    For individual domains that you wish to add the HSTS headers to, you can simply add the configuration rule(s) to: /etc/apache2/conf.d/userdata/ssl/2_4/$user/$domain/$includename.conf

    For example:
    Code:
    [/etc/apache2/conf.d/userdata/ssl/2_4/forumuser/forumuser.io]# cat hsts.conf
    Header always set Strict-Transport-Security "max-age=31536000"
    I hope this helps!
     
  3. fonginator

    fonginator Registered

    Joined:
    Oct 19, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    76
    Location:
    Montreal, Canada
    cPanel Access Level:
    Root Administrator
    Hi David,

    This is ultimately what I ended up having to do, but I find it to be less convenient since it requires root access (something which I don't necessarily have on all of the cPanel servers I plan to help roll out EA4 on) and breaks existing EA3 configurations.

    Unless I'm missing something, putting this in the .htaccess file should work which is the most troublesome aspect of this. I wish I could understand whether this is a bug or some sort of side effect of going from mod_php/mod_ruid2 in EA3 to an fcgi setup with EA4.
     
  4. linux4me2

    linux4me2 Well-Known Member

    Joined:
    Aug 21, 2015
    Messages:
    168
    Likes Received:
    36
    Trophy Points:
    28
    Location:
    USA
    cPanel Access Level:
    Root Administrator
    I'm using EA4 (v. 58.0.32) with Event MPM and suPHP, and I can confirm that the "set" command is working on an account's .htaccess based on the results from testing it on observatory.mozilla.org:
    Code:
    <IfModule mod_headers.c>
      Header set Strict-Transport-Security "max-age=15768000"
    </IfModule>
    
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello @fonginator,

    Feel free to open a support ticket using the link in my signature so we can take a closer look. You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
  6. DomineauX

    DomineauX Well-Known Member
    PartnerNOC

    Joined:
    Apr 12, 2003
    Messages:
    421
    Likes Received:
    6
    Trophy Points:
    168
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Was any solution ever found for this?
    Seeing the same issue when trying to use the following in .htaccess files under EasyApache 4:

    Header append X-FRAME-OPTIONS "SAMEORIGIN"

    Works for .html files, but not .php scripts.
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you let us know which PHP version and handler is utilized for the accounts you are testing this with?

    Thank you.
     
  8. DomineauX

    DomineauX Well-Known Member
    PartnerNOC

    Joined:
    Apr 12, 2003
    Messages:
    421
    Likes Received:
    6
    Trophy Points:
    168
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Apache/2.4.23 prefork
    PHP 7.0.13
    CGI Handler
     
  9. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    This is likely due to the use of the CGI handler for PHP. You can read more about the interaction between CGI and Mod_Headers at:

    mod_headers - Apache HTTP Server Version 2.4

    Were you using CGI as the PHP handler before the conversion to EasyApache 4? If not, you should consider changing it back to the previously configured PHP handler. Information on changing the PHP handler is available at:

    PHP Handlers - EasyApache 4 - cPanel Documentation

    Let us know if this helps.

    Thank you.
     
  10. DomineauX

    DomineauX Well-Known Member
    PartnerNOC

    Joined:
    Apr 12, 2003
    Messages:
    421
    Likes Received:
    6
    Trophy Points:
    168
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    It was using SuPHP on EA3.
    After switching to SuPHP, it is now working.
     
    cPanelMichael likes this.
  11. asuna123

    asuna123 Registered

    Joined:
    Jan 16, 2017
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    indonesia
    cPanel Access Level:
    Website Owner
    was any solution this problem?
    on .htaccess under EA4

    <IfModule mod_header.c>
    Header Set Cache-Control"max_age=3600"
    <IfModule>

    this is not work

    <IfModule mod_header.c>
    Header Set Cache-Control"max-age=3600"
    <IfModule>
     
  12. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Could you let us know which PHP handler is enabled on the system?

    Thank you.
     
  13. yaashul

    yaashul Registered

    Joined:
    May 3, 2017
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    India
    cPanel Access Level:
    Root Administrator
    I am facing this problem still. Running the latest easyapache 4.

    I am not able to set any header for the pages created by mod_rewrite or basically php pages. Rest of the images are showing the right headers. I am using FastCGI PHP FPM. Does anyone has ever found a solution for the same?
     
  14. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Are you able to reproduce the issue when using a non-CGI handler such as DSO or suPHP?

    Thank you.
     
Loading...

Share This Page