Fun with Mono.NET
patrick — Wed, 2006-10-18 18:16
Whee! That was fun. Ok, so I set up mono way back in January or February hoping I could show off some of my old ASP (not .NET) applications that I had worked on. After getting everything set up, writing a "Hello World" page, getting that to actually display, & heading off to discover if I could get my VB ASP code to work I discovered that all the time I had put into setting up mono was a complete waste of time. Mono won't run the old VB ASP code.
Granted I knew before setting up Mono that getting the Access databases to work on linux would be impossible & I figured I could export them to SQL or CSV & import them into MySQL. Trying to fix the ODBC connectivity might take some doing, but I could probably mess with unixODBC & get that working... I could modify the ASP code slightly to make up for these issues if I needed to. I'm glad I waited to get all of this conversion stuff I had been planning on doing until after I figured out how to get the VB ASP code to work...
With my recent delving into Ruby on Rails, thoughts about delving into Adobe Flex 2.0, a post I'm working on about Linux Distros (I'm getting tired of repeating myself), & a friend of mine looking at learning C#.NET (via mono) - I figured what the hell? I'll go the distance & make sure mono still works on my server... Maybe do a couple initial "Hello World" pages or something.
"500 Internal Server Error"
Huh? I open up the apache vhosts file & check it out. I typed the directory name wrong in the URL. I fix my error in the browser & press enter.
I don't remember the exact error, but it was something about the website being down for maintenance, please contact the server administrator. Ok, considering I am my server administrator that's not helpful. I do some google searches for apache2, mod-mono, howto, & debian. The 1st item that comes up I read through it, check my configuration files & notice that my configuration files are basically the same thing (only slightly different as I'm using a different directory for my .NET stuff). No good.
I check the 2nd page on how to set stuff up & I'm seeing some different information so I readjust my config file for my apache vhost, restart apache, refresh my browser, & "500 Internal Server Error"... Ok, this isn't good - it's the same as my 1st error.
Checking some information elsewhere I find some new information so I try that & I end up with something that looks like my 2nd error, but makes me think that there might be some permission issues with the filesystem. I Alt+Tab over to PuTTY, CTRL+A+D to close the screen session I'm in, "screen -r 13" to load the other screen session where I'm in the .NET directory, & check permissions. The web server group has read permissions on most files, others have no permissions on most things except to get into the directory. Hmm... maybe mod-mono is trying to access the directory as it's own user? I give read permission only on all the *.aspx* files in the directory. I hit refresh in the web browser & instead of the error I got before changing permissions I now get a "500 Internal Server Error" again. What's going on??
tail /var/log/apache2/error.log
Ok, that's a bunch of lines saying, "Another mod-mono-server with the same arguments is already running." This isn't very helpful, but does tell me that it is trying to at least do something. So I type "echo '' >> /var/log/apache2/error.log", arrow up & enter again so I get 2 blank lines at the end of the error.log file. I restart apache, run tail again, & all I get is the same annoying message about "another mod-mono-server blah blah" showing up after my 2 blank lines.
I really didn't want to go to the mono website & read through the material there. The few pages I saw referencing the mono website docs didn't sound to promising. I ended up at ApacheWorld's Mod Mono page which basically says their docs are to old - go download mod mono from the mono project's webpage & use their docs. Fine. I follow the link & head for the "manuals & docs" section only to be greeted by a bunch of stuff I'm not wanting to delve into at this point. I go back & do a search for apache.
Search results
From Mono
For query "apache"
No page with this exact title exists, trying full text search.
For more information about searching Mono, see Searching Mono.
Showing below up to 20 results starting with #1.
I skip the "1. faq.old" link because I don't want to waste my time rehashing old stuff. "2. FAQ: Technical" looks good, but after spending a bit of time searching the page for apache it doesn't look useful. I skip "3. FAQ: Licensing" & "4. Mono Project Roadmap".
"5. ASP.NET", looks to contain info on mod_mono & apache, let's hope it's good. You have 2 choices for running ASP.NET applications with mono - mod_mono on apache or XSP. Blah blah blah mod_mono... blah blah blah mod_mono... blah blah blah mod_mono. Ok, I get the hint & go to the mod_mono project page. 3rd section down is "Distribution-Specific Documentation" & the only link is for "Mod_Mono on Ubuntu". I skipped that since my server is running Debian & end up at "Configuring Mod_Mono".
There's a simple 6 lines worth of code for apache configuration. I check "/etc/apache2/mods-enabled/mod_mono.load", "/etc/apache2/mods-enabled/mod_mono.conf", & my vhost file for "patrick.blogdns.org".
Aha! On the mod_mono page is shows AddMonoApplications default "/test:/usr/share/doc/xsp/test" & my vhost file has MonoApplications "/net:/path/to/my/dot/net/app" - there's another section a bit lower down that has more vhost configuration options. I dig through them & add the MonoDocumentRootDir "/path/to/my/dot/net/app" to my vhost file. The other apache config sections I already have in 1 file or another or do not seem to be what I need.
I restart apache & refresh my page. "The website is down, probably for maintenance. Please contact the site administrator." Ok, so whatever that was that I did wasn't the right thing to do.
I go back up, click the link for "Mod_Mono on Ubuntu", & am greeted by a message stating that Ubuntu packages mod_mono very differently than the official distribution... Ok, I knew that because Ubuntu is based on Debian & Debian seems to have packaged mono differently because nothing I've tried so far seems to work.
I check my installed packages & I already have libapache2-mod-mono & mono-apache-server2 installed. I run a2enmod mod_mono & get a message stating that "This module is already enabled!". Hmm... ok, what if I purge all of the mono packages I currently have installed?
I run
out=""; for i in `aptitude search mono | grep ^i | sed -r "s/i A/iA /" | awk -F\ '{print $2}'`; do out="$out $i"; done; echo $out
for those that can't read that, here's a line by line -
out="";
for i in `aptitude search mono |
grep ^i |
sed -r "s/i A/iA /" |
awk -F '{print $2}'`; do
out="$out $i";
done;
echo $out
which then created this list -
libapache2-mod-mono libmono-accessibility2.0-cil libmono-corlib1.0-cil libmono-corlib2.0-cil libmono-data-tds2.0-cil libmono-microsoft-build2.0-cil libmono-peapi2.0-cil libmono-security2.0-cil libmono-sharpzip2.84-cil libmono-system-data2.0-cil libmono-system-web2.0-cil libmono-system2.0-cil libmono-winforms2.0-cil libmono0 libmono2.0-cil mono-apache-server mono-apache-server2 mono-classlib-1.0 mono-classlib-2.0 mono-common mono-gac mono-gmcs mono-jit mono-mcs mono-runtime mono-xsp-base mono-xsp2-base
so I could then do this -
aptitude purge libapache2-mod-mono libmono-accessibility2.0-cil libmono-corlib1.0-cil libmono-corlib2.0-cil libmono-data-tds2.0-cil libmono-microsoft-build2.0-cil libmono-peapi2.0-cil libmono-security2.0-cil libmono-sharpzip2.84-cil libmono-system-data2.0-cil libmono-system-web2.0-cil libmono-system2.0-cil libmono-winforms2.0-cil libmono0 libmono2.0-cil mono-apache-server mono-apache-server2 mono-classlib-1.0 mono-classlib-2.0 mono-common mono-gac mono-gmcs mono-jit mono-mcs mono-runtime mono-xsp-base mono-xsp2-base
Now that all the mono packages are gone I need to remove some left over chaff. I delete /etc/mono-server/, /etc/mono-server2/, /etc/apache2/mods-available/mod_mono.load, & /etc/apache2/mods-available/mod_mono.conf & then make sure the soft links in /etc/apache2/mods-enabled/ for mod_mono are deleted as well. Now we can install everything fresh -
aptitude install libapache2-mod-mono mono-apache-server2
a2enmod mod_mono
"This module is already enabled!" Ok, I was kind of expecting that, but anyways... I restart apache, refresh my browser, & the stupid message about the website being down for maintenance, please contact myself. I go find a mirror & complain about the fact that the server is not working - just kidding.
I read the man pages for xsp & find alot of options, but nothing that really tells how to put these .webapp files together. I check out the "Example Configuration" section, comment out a bunch of stuff from my vhost file that references my .NET stuff & paste in the Directory options listed. I created a /home/username/workspace/websites/patrick.blogdns.org.webapp file, copied the file contents off the page, changed the values to reflect my setup, created a soft link in /etc/mono-server2/ to /home/username/workspace/websites/patrick.blogdns.org.webapp, restarted apache, & refresh the browser.
Success! I finally saw "Hello World". I've never really been interested in writing "Hello World" apps, but they're always a nice way to make sure you really have your environment setup.