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!

System-Wide Apache Handler and MIME Types

Discussion in 'EasyApache' started by Jim_WHM, Jun 12, 2014.

  1. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I have a site that i recoded into php from aspx but I kept the file extensions .aspx so I wouldn't have to 301 redirect everything.
    On the cPanel level, for an individual account I know how to add and apache handler and MIME type to make the .aspx file run as .php. But what this actually does is creates a .htaccess file in the /public_html folder with the following lines:
    AddType application/x-httpd-php5 .aspx
    AddHandler application/x-httpd-php5 .aspx


    What I'd really like to do is avoid .htaccess files and put this in the httpd.conf file. I believe this would be faster and there's no possibility of the .htaccess file might get replaced/deleted thereby exposing php code as pure text on the server. But I know that httpd.conf gets messed up when EasyApache is ran. Is there a proper way to do this so using EasyApache/WHM/cPanel wont mess things up?
     
  2. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    834
    Likes Received:
    29
    Trophy Points:
    178
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    Try editing httpd.conf and finding this block:

    Code:
    <IfModule mime_module>
        TypesConfig conf/mime.types
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
    
    </IfModule>
    
    Add it within that block and run:

    Code:
    /usr/local/cpanel/bin/apache_conf_distiller --update
    

    I didn't actually try this, but theoretically it should work by applying the change to the config templates so it is retained during updates.

    If that doesn't work, go into /var/cpanel/templates/apache2, copy main.default to main.local, add the config to main.local, and run:

    Code:
    /scripts/rebuildhttpdconf
    service httpd restart
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Should I add AddHandler application/x-httpd-php5 .aspx anywhere too?
     
  4. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks a ton. It works. All i had to do was:
    - insert 'AddType application/x-httpd-php5 .aspx' into the block you showed
    - ran '/usr/local/cpanel/bin/apache_conf_distiller --update'
    - restarted Apache

    I guess I don't need to set an AddHandler anywhere
     
  5. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I didn't do the 2nd part of what your post suggested. Should i also do that or will what I've done survive EasyApache/WHM updates?
     
  6. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,400
    Likes Received:
    1,951
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello :)

    Your changes are preserved if you ran the Apache distiller.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    834
    Likes Received:
    29
    Trophy Points:
    178
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    The second part was an alternative suggestion in case the first solution I gave didn't work.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks a lot guys worked great!
     
  9. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Actually I just rebuilt apache using EasyApache and my .aspx pages were showing as pure text code again. So I guess
    /usr/local/cpanel/bin/apache_conf_distiller --update
    didn't work right.

    I tried your 2nd solution but wasn't 100% sure where to insert the lines. A lot of places in the main.local file say not to edit it.
     
  10. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    834
    Likes Received:
    29
    Trophy Points:
    178
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    Same section. Look for this:

    Code:
    <IfModule [% main.mainifmodulemimemodule.item.ifmodule %]>
        TypesConfig [% main.ifmodulemimemodule.typesconfig.item.typesconfig %]
    [% FOREACH dir IN main.ifmodulemimemodule.addtype.items -%]
        AddType [% dir.mime %] [% dir.extension %]
    [% END -%]
    
    Add the additional settings after END, but before the closing </ifmodule>. That *might* work.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks I did the edit and ran
    /scripts/rebuildhttpdconf
    service httpd restart

    And I will rerun EasyApache some time tomorrow just to see if it survives.
     
  12. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I reran Easy Apache and unfortunately the changes did not stick.
     
  13. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,400
    Likes Received:
    1,951
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Could you outline the specific steps you took so we can verify if it's the correct method?

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Sure I just did it again to make sure everything i write is exact:

    - The httpd.conf file has not been edited by me, it's fresh off an EasyApache build.
    - Logged into SSH with root
    - cd to /var/cpanel/templates/apache2
    - cp main.default main.local
    - vim main.local
    - did vim search for 'main.mainifmodulemimemodule.item.ifmodule'
    - found it. and edited the block to look like this:

    PHP:
    <IfModule [% main.mainifmodulemimemodule.item.ifmodule %]>
        
    TypesConfig [% main.ifmodulemimemodule.typesconfig.item.typesconfig %]
    [% FOREACH 
    dir IN main.ifmodulemimemodule.addtype.items -%]
        
    AddType [% dir.mime %] [% dir.extension %]
    [% 
    END -%]
        
    AddType application/x-httpd-php5 .aspx

    </IfModule>
    - saved and quit vim
    - ran '/scripts/rebuildhttpdconf' by just typing '/scripts/rebuildhttpdconf' in the commandline. It said '/usr/local/apache/conf/httpd.conf OK'.
    I thought my httpd.conf file would be at '/etc/httpd/conf/httpd.conf' ? Nevermind one of these paths must be a symbolic link to the
    same spot.

    - restarted apache using 'service httpd restart'
    - Saw no changes in '/etc/httpd/conf/httpd.conf' or '/usr/local/apache/conf/httpd.conf' yet. As in 'AddType application/x-httpd-php5 .aspx' was not added to the httpd.conf file at this point. Same file probably I know (symbolic link)..

    - Then reran EasyApache from WHM (Previously Saved config profile) and rebuilt it w/out changing any options.
    - saw that 'AddType application/x-httpd-php5 .aspx' was still not added to httpd.conf and my site's .aspx files showed as pure text.
     
  15. Jim_WHM

    Jim_WHM Member

    Joined:
    Jun 12, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Ok I found that my problem was that I should have been changing the files in this directory instead:
    /var/cpanel/templates/apache2_4
    not /var/cpanel/templates/apache2

    I haven't rebuilt apache yet but I think it will probably work because /scripts/rebuildhttpdconf inserted it correctly into httpd.conf.
     
  16. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,400
    Likes Received:
    1,951
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    I am happy to see you were able to resolve the issue. Thank you for updating us with the outcome.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice