How to install Mono on RedHat/Plesk 8.6.x

Mono is a savior if you’re migrating Windows sites to Linux/Apache stack. I had to do this just recently and had to setup Mono on RHEL box with Plesk 8.6. It was relatively straighforward process and here is quick log as to how installed Apache Mono on Plesk:

1. Add Mono repository to yum:


wget -O /etc/yum.repos.d/mono.repo http://ftp.novell.com/pub/mono/download-stable/rhel-4-i386/mono.repo

2. Install Mono:

yum install mono-core mono-web mono-data mod_mono xsp

Note: You may get missing dependency notice.

Missing Dependency: libexif.so.9 is needed by package libgdiplus0-1.9-1.rhel4.novell.i386 (mono)
Error: Missing Dependency: libexif.so.9 is needed by package libgdiplus0-1.9-1.rhel4.novell.i386 (mono)
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest

If that’ the case you’ll need to take a different route. Remove that /etc/yum.repos.d/mono.repo and create a new file centos-5-extras.repo and put the folloging content in there:

[centos-5-extras]
name=CentOS-5 - $basearch - Extras
#baseurl=http://mirror.centos.org/centos/5/extras/$basearch/
mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
enabled=0

Then run this:

yum --enablerepo=centos-5-extras install mono-core mono-web mono-data mod_mono xsp

This should do it. Just make sure mono is installed afterwards:

mono -V

3. Check & configure mod_mono
Install process should’ve created the configuration file for mod_mono. Check if it exists here: /etc/httpd/conf.d/mod_mono.conf
If it doesn’t exist there create it and put the following contents:

# mod_mono.conf
<IfModule !mod_mono.c>
LoadModule mono_module /usr/lib/httpd/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
DirectoryIndex index.aspx
DirectoryIndex Default.aspx
DirectoryIndex default.aspx
</IfModule>

4. Restart Apache

/usr/local/psa/admin/sbin/websrvmng -r

This did it for me. Along the way I encountered few issues, looking closesly at /var/log/httpd/error_log helped to find solutions(in my case it was missing mono-web package, that brings in System.Web library I guess).

Apache 2 and HTTP Authentication with PAM

There are 2 ways(at least that I know of) to get Apache 2 to use PAM for http auth:

  • Old mod_auth_pam, which I believe is not developed anymore and also posses some security risks
  • Newer mod_authnz_external and pwauth

This little write up shows how to get Apache and PAM going on Ubuntu using the mod_authnz_external.
To get started, let’s install some packages:

sudo apt-get install libapache2-mod-authnz-external pwauth
sudo apt-get install libapache2-mod-authz-unixgroup
sudo a2enmod authnz_external authz_unixgroup

Edit config file for the Virtual Host you’d like to get them PAM-based HTTP Authentication going, such that it contains the following clause:


<IfModule mod_authnz_external.c>
AddExternalAuth pwauth /usr/sbin/pwauth
SetExternalAuthMethod pwauth pipe
</IfModule>

And the final bit of configuration goes to your Directory definition inside of vhost block:

<Directory /var/www/yourlocation>
AuthType Basic
AuthName "Restricted Area"
AuthBasicProvider external
AuthExternal pwauth
Require user john

# some other configuration statements
</Directory>

This will allow user john to access the resource.

Now if you also want to have PAM authentication by users group you’ll need to make few extra steps. Missing bit of puzzle here is called ‘unixgroup’ script and for some reason it is not in Ubuntu’s pwauth package where it ought to be. You will need to grab it from here and copy it over to /usr/sbin/unixgroup and make it executable. Here is a quick snippet to do that:


wget "http://pwauth.googlecode.com/files/pwauth-2.3.9.tar.gz"
tar xzvf ./pwauth-2.3.9.tar.gz
sudo cp pwauth-2.3.9/unixgroup /usr/sbin/
sudo chmod a+x /usr/sbin/unixgroup

Once that’s done, you’ll need to few more lines to you Virtual Host config, so it will look something like this:

<IfModule mod_authnz_external.c>
AddExternalAuth pwauth /usr/sbin/pwauth
SetExternalAuthMethod pwauth pipe
AddExternalGroup unixgroup /usr/sbin/unixgroup
SetExternalGroupMethod unixgroup environment

</IfModule>

<Directory /var/www/yourlocation>
AuthType Basic
AuthName "Restricted Area"
AuthBasicProvider external
AuthExternal pwauth
GroupExternal unixgroup
Require user john# some other configuration statements
</Directory>

Hopefully this is helpful to someone besides myself :) Let me know if you got stock somewhere along the way.