Serving ASP.NET pages in Apache on CentOS 5
I’m starting to love ASP.NET and the ability to do everything in C# (I’m currently working on an internal silverlight app at work and creating a RESTful API is more fun in C#). Anyway, you can do a yum install mod_mono, but it’s a pretty old version so I did some research and found a guide on building it yourself along with two other guides that were roughly the same, but not as good… (1, 2) and somehow ended up with a working server. This is a companion to that guide with more up to date versions of things. (it took me SEVERAL trial and error attempts to get things working :/ so hopefully i didn’t miss any steps)
Let me preface this with the fact that if you’re running one of the already supported OSs (debian or unbuntu for instance) you shouldn’t follow this guide – instead you should just look on the mono website for information.
First thing I did was grab the most up-to-date mono and xst sources (i matched versions)
cd /tmp wget http://ftp.novell.com/pub/mono/sources/mono/mono-2.6.tar.bz2 wget http://ftp.novell.com/pub/mono/sources/mod_mono/mod_mono-2.6.tar.bz2 wget http://ftp.novell.com/pub/mono/sources/xsp/xsp-2.6.tar.bz2
Then unpack everything
tar -jxvf mono-2.6.tar.bz2 tar -jxvf xsp-2.6.tar.bz2 tar -jxvf mod_mono-2.6.tar.bz2
then build mono first (change anything on the ./configure line to your liking, I do suggest picking a place to put mono, letting it install wherever it wants to makes the rest of the process very painful!):
cd /tmp/mono-2.6 ./configure --prefix=/opt/mono make ; make install echo export PKG_CONFIG_PATH=/opt/mono/lib/pkgconfig:$PKG_CONFIG_PATH>>~/.bash_profile echo export PATH=/opt/mono/bin:$PATH>>~/.bash_profile source ~/.bash_profile
after a bit you’ll have mono installed
Now build xsp (i had to add pkgconfig to an environment variable to get it to work)
cd /tmp/xsp-2.6 ./configure --prefix=/opt/mono make ; make install
Finally build mod_mono, you’ll probably need to tell it where apache’s apr-config is… it took a while for me to find it.. heh
find / -iname apr*config cd /tmp/mod_mono-2.6 ./configure --prefix=/opt/mono --with-mono-prefix=/opt/mono --with-apr-config=/usr/bin/apr-1-config make ; make install
you should now find mod_mono in your apache modules dir (in my case /usr/lib64/httpd/modules/)
ls /usr/lib64/httpd/modules/mod_mono* 17 Feb 5 22:54 /usr/lib64/httpd/modules/mod_mono.so -> mod_mono.so.0.0.0 145511 Feb 5 22:54 /usr/lib64/httpd/modules/mod_mono.so.0.0.0
the mod_mono install seems to have automatically created mod_mono.conf in my httpd/conf folder, but you may want to make sure it’s there
vim /etc/httpd/conf/mod_mono.conf
# mod_mono.conf
# Achtung! This file may be overwritten
# Use 'include mod_mono.conf' from other configuration file
# to load mod_mono module.
<IfModule !mod_mono.c>
LoadModule mono_module /usr/lib64/httpd/modules/mod_mono.so
</IfModule>
<IfModule mod_headers.c>
Header set X-Powered-By "Mono"
</IfModule>
AddType application/x-asp-net .aspx
AddType application/x-asp-net .asmx
AddType application/x-asp-net .ashx
AddType application/x-asp-net .asax
AddType application/x-asp-net .ascx
AddType application/x-asp-net .soap
AddType application/x-asp-net .rem
AddType application/x-asp-net .axd
AddType application/x-asp-net .cs
AddType application/x-asp-net .vb
AddType application/x-asp-net .master
AddType application/x-asp-net .sitemap
AddType application/x-asp-net .resources
AddType application/x-asp-net .skin
AddType application/x-asp-net .browser
AddType application/x-asp-net .webinfo
AddType application/x-asp-net .resx
AddType application/x-asp-net .licx
AddType application/x-asp-net .csproj
AddType application/x-asp-net .vbproj
AddType application/x-asp-net .config
AddType application/x-asp-net .Config
AddType application/x-asp-net .dll
DirectoryIndex index.aspx
DirectoryIndex Default.aspx
DirectoryIndex default.aspx
Now, you need to get this to work with ISPConfig3, since if you’ve followed my other tutorials, that’s what you have running things on the back end.
Modify your httpd.conf file to include mod_mono.conf. You want to do this at the very bottom, just before the NameVirtualHost directives (ISPConfig puts 3 directives at the very bottom of httpd.conf, you want to place this line just before them:
vim /etc/httpd/conf/httpd.conf
Include /etc/httpd/conf/mod_mono.conf # this is where ISPConfig's stuff is, don't modify it, this comment is so you know where to put the line above the commentNameVirtualHost *:80 NameVirtualHost *:443 Include /etc/httpd/conf/sites-enabled/
now, restart apache
service httpd restart
and open up ISPConfig. go to sites > website > Select the website you want to add a mono enabled directory to, then click on the “Options” tab for that site. Enter the following into the Apache Directives (replace /var/www/path/to/the/web/folder with the path to that site’s web folder)
MonoPath default "/opt/mono/lib/mono/2.0" MonoServerPath default /opt/mono/bin/mod-mono-server AddMonoApplications default "/test:/var/www/path/to/the/web/folder/test" <location /test> MonoSetServerAlias default SetHandler mono </location>
and finally restart httpd
service httpd restart
here’s a test page, create it in your /var/www/path/to/the/web/folder/test directory and set the permissions to whatever the other site’s permissions are, or apache.apache
<html>
<body>
<% Response.Write("Hello World!"); %>
</body>
</html>
now, once ISPConfig restarts apache (sometimes this is instant but i’ve seen it take up to 5 minutes) you’ll see Hello World! displayed
February 20th, 2010 - 14:44
I have followed these directions, and I end up with a “Server Error in /test Application”. Do you have any suggestions on where to look for the errors this generated so that I can further troubleshoot?
I’d like to thank you though, as your tutorial is the closest I’ve gotten to get this to work. Prior to finding this, I’d been getting 500 server errors.
March 17th, 2010 - 15:35
I’m sorry I didn’t notice your comment sooner… it looks like my server isn’t notifying me via e-mail when new comments are posted!
Do you have any more information on this, or have you already discovered the solution? I’ve kind of given up on ASP right now since I realized the API I needed to make would be hosted on FreeBSD which has a port of mono that’s even more out of date than mono is (to the API.NET stuff)