Jim_WHM

Member
Jun 12, 2014
16
0
1
cPanel Access Level
Root Administrator
These are old threads of mine where I described how i wanted to permanently change the httpd.conf file to add system-wide mime types to make an .aspx file be ran as a php file and also get rid of the mysite.tld/whm and mysite.tld/cpanel shortcuts.

System-Wide Apache Handler and MIME Types

Disable mysite.tld/whm And mysite.tld/cpanel Shortcuts?

I am now migrating to a EA4 server from and EA3 server and I want to know if the process is still the same. What i did before on my EA3 server was this:


- Logged into SSH with root changed dir to /var/cpanel/templates/apache2_4
- cp main.default main.local
- vim main.local and did vim search for 'main.mainifmodulemimemodule.item.ifmodule'
- found it. and edited the block to look like this:
<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>

- vim searched for "main.scriptaliasmatch.items" AND REMOVED THESE 3 LINES from the main.local file:
[% FOREACH dir IN main.scriptaliasmatch.items -%]
ScriptAliasMatch [% dir.regex %] [% dir.path %]
[% END -%]

- saved and quit vim
- ran '/scripts/rebuildhttpdconf' by just typing '/scripts/rebuildhttpdconf' in the commandline. It said '/usr/local/apache/conf/httpd.conf OK'.
- restarted apache using 'service httpd restart'
- ran EasyApache to rebuild Apache/php and the changes to httpd.conf survived! So Success in EA3.
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463

Jim_WHM

Member
Jun 12, 2014
16
0
1
cPanel Access Level
Root Administrator
Thanks for the links and hints Michael.

I ended up adding these lines to the WHM httpd.conf include editor (WHM »Home »Service Configuration »Apache Configuration »Include Editor) in "Pre VirtualHost Include" for "All Versions" and it seemed to do the trick.

AddHandler application/x-httpd-ea-php70 .aspx
AddType application/x-httpd-ea-php70 .aspx


If you can think of a reason this is a bad idea let me know. I also added a .htaccess file with the same commands for backup in case EasyApache messes something up down the line. It's real important my aspx files are processed as php and the code not just served up as text.

One concern is if php is upgraded either automatically or i do it myself forgetting that it will break the AddType command then all my code will be served up as text until i fix the AddType command to use the new php handler.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
One concern is if php is upgraded either automatically or i do it myself forgetting that it will break the AddType command then all my code will be served up as text until i fix the AddType command to use the new php handler.
This is the primary concern you will face when adding that custom AddHandler entry. You may want to consider using the following UAPI function via the command line to quickly enable that custom Mime type for all accounts:

UAPI Functions - Mime::add_mime - Software Development Kit - cPanel Documentation

You could also setup a script that utilizes that UAPI function and then runs it automatically as a hook during account creation.

Thank you.