System-Wide Apache Handler and MIME Types
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?
-
Try editing httpd.conf and finding this block: TypesConfig conf/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz
Add it within that block and run:/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:/scripts/rebuildhttpdconf service httpd restart0 -
Should I add AddHandler application/x-httpd-php5 .aspx anywhere too? 0 -
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 0 -
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? 0 -
Hello :) Your changes are preserved if you ran the Apache distiller. Thank you. 0 -
[quote="Jim_WHM, post: 1663272">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?
The second part was an alternative suggestion in case the first solution I gave didn't work.0 -
Thanks a lot guys worked great! 0 -
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. 0 -
[quote="Jim_WHM, post: 1667031">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.
Same section. Look for this: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 . That *might* work.0 -
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. 0 -
I reran Easy Apache and unfortunately the changes did not stick. 0 -
[quote="Jim_WHM, post: 1667061">Thanks I did the edit and ran /scripts/rebuildhttpdconf service httpd restart
Could you outline the specific steps you took so we can verify if it's the correct method? Thank you.0 -
[quote="cPanelMichael, post: 1668742">Could you outline the specific steps you took so we can verify if it's the correct method? Thank you.
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] 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 [/PHP] - 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.0 -
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. 0 -
I am happy to see you were able to resolve the issue. Thank you for updating us with the outcome. 0
Please sign in to leave a comment.
Comments
15 comments