There are a variety of ways to install Mono. I elected to use CentOS version 5 as the base operating system, and since this is basically RedHat Enterprise Server with some simple re-branding, it seemed that the best way to do this was via the Yum package manager. Well, this sounds great in theory, but it broke. It turns out that binaries created for CentOS 4 are not exactly compatible with CentOS 5.
Who knew?
So, it's back to an installation from source. Fortunately, this is not terribly difficult. Here is the basic system/software I was installing on:
- CentOS 5
- Dual Core Pentium IV processor (3 GHz)
- Apache 2.0.59
- Mono 1.2.4
Apache is installed from source -- I can't help it. I like to know exactly what's installed, and how it's configured; I still don't trust RPMs.
I elected to install Mono in /opt. The directory didn't exist, so I first created it. I logged in, su-d to root, and created the directory:
[root@luther]# cd /
[root@luther]# mkdir opt
Then I changed to the newly created directory, and downloaded the necessary files. In order to serve .aspx files, we need the mono base, the XSP server, and mod_mono. I got all those files using the trust wget application:
[root@luther]# cd opt
[root@luther]# wget http://go-mono.com/sources/mono/mono-1.2.4.tar.bz2
[root@luther]# wget http://go-mono.com/sources/xsp/xsp-1.2.4.tar.bz2
[root@luther]# wget http://go-mono.com/sources/mod_mono/mod_mono-1.2.4.tar.bz2
Now, upack everything:
[root@luther]# tar jxvmfp *.bz2
Change to the newly created mono-1.2.4 directory, and configure mono. Notice the parameter I passed the configure program; it tells it to install mono in /opt/mono. I then make, and make install the application.
[root@luther]# cd mono-1.2.4
[root@luther]# ./configure --prefix=/opt/mono
[root@luther]# make ; make install
Wait a bit, and voila -- you have the mono base installed. Now let's do the same thing for Xsp. Xsp is the web server for mono -- it handles the compilation and delivery of .aspx files. This is pretty simple as well:
[root@luther]# cd ../xsp-1.2.4
[root@luther]# ./configure --prefix=/opt/mono
[root@luther]# make ; make install
If "configure" or "make" complains about not finding something, try executing this:
[root@luther]# export PATH=/opt/mono/bin:$PATH
Then run the above commands again.
Now, on to mod_mono:
[root@luther]# cd ../mod_mono-1.2.4
[root@luther]# ./configure --prefix=/opt/mono \
--with-mono-prefix=/opt/mono \
--with-apr-config=/usr/local/apache2/bin/apr-config
[root@luther]# make ; make install
When this is done, if you go to /usr/local/apache2/modules (or wherever you told it apache lives) and look at the files there, you should see these: mod_mono.so (a symlink) and mod_mono.so.0.0.0. These are the modules (well, there's only really one -- mod_mono.so is a pointer to mod_mono.so.0.0.0) that apache needs to invoke xsp and deliver .aspx files.
Now we need to configure apache.
Open the apache configuration file with your fvourite editor (we'll use vi):
[root@luther]# vi /usr/local/apache2/conf/httpd.conf
Go to the bottom of that file, and append this text:
<IfModule !mod_mono.c>
LoadModule mono_module /usr/local/apache2/modules/mod_mono.so
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 .config
AddType application/x-asp-net .Config
AddType application/x-asp-net .dll
AddType application/x-asp-net .asp
DirectoryIndex index.aspx
DirectoryIndex Default.aspx
DirectoryIndex default.aspx
</IfModule>
Now, we'll configure a virtual host to serve up the test suite that ships with mono. In the virtual host section of your file, put in something like this:
<VirtualHost 198.xxx.xxx.xxx:80>
DocumentRoot /home/httpd/aspx/html
ServerName aspx.yoursite.com
Alias /demo /opt/mono/lib/xsp/test
MonoApplications "/demo:/opt/mono/lib/xsp/test"
MonoServerPath /opt/mono/lib/mono/1.0/mod-mono-server.exe
<Directory /opt/mono/lib/xps/test>
SetHandler mono
</Directory>
</VirtualHost>
Note that you should specify your actual DocumentRoot and IP address to whatever you are using. This tells Apache that everything served under http://aspx.yoursite.com/demo is actually found in /opt/mono/lib/xsp/test, and handled by mono.
Restart apache, and go to http://aspx.yoursite.com/demo/index.aspx
You should see the full mono test suite.
Cool, eh?
Note that with this configuration, I can also put aspx files right in the document root for my virtual host, and they will be handled by mono as well. For example, I put this in the root level of the web server and called it test.aspx:
<html>
<body>
<% Response.Write("Hello World!"); %>
</body>
</html>
And it compiled and worked just fine.