How to configure Mono in Apache (QNAP TS-210)
Posted: Sun Sep 12, 2010 11:16 pm
This article will present you how you can configure your QNAP NAS (in my case TS-210) to run Mono project plus configure Apache web server to serve .Net (aspx, mvc etc) web sites.
The procedure you must follow is the following:
First of all you have to install Mono for QNAP (2.4.2.3) through a QPKG package (download it from here http://www.turbonas.com/phpBB3/viewtopic.php?f=18&t=942) and the upload it to qnap through QNAP administration console. The installation folder by QPKG will be: /share/HDA_DATA/.qpkg/mono.
Now you have to install through IPKG Apache2 (QNAP has pre installed Apache 1.3 as its web server but with this version its not simple to install mod-mono). Again into your NAS prompt the command:
As you can see Apache2 is installed into Optware folder in your NAS (/share/HDA_DATA/.qpkg/Optware/) but has an error in his configuration and cannot start. The error exists in file "/share/HDA_DATA/.qpkg/Optware/etc/apache2/httpd.conf" which is the main configuration file of the Apache2. The error exists in the point that says:
Here you must change these lines and put as user and group the guest so it will be:
You have also to change the basic port this server listen in place of that file "Listen 8000" and put it a port different from basic NAS' apache web server eg: "Listen 8888". Now you apache will listen the address "http://NasAddress:8888/".
After all you have to restart your new apache2 web server and everything will be ok on your NAS by the command:.
One usefull configuration in "httpd.conf" is to configure an error file to write inside in order to know whether Apache started or not. use a local file in your NAS disk such as:
Next Step is to install mod_mono module into your NAS. This module is responsible in order to provide ASP .NET support in Apache. The tricky thing is that there is not officially any point of getting this module and I tested many versions up to the moment to make it run. Through the list of debian packages for libapache2-mod-mono (http://packages.debian.org/search?searc ... 2-mod-mono) What it worked was the "lenny-backports" one and more specifically the "armel" version. However as your NAS has not installed a debian linux cannot use the .deb file of this module in order to install it so you have to do it manually. What you have to do is to use your Linux Archive Manager tool and open the .deb file and unzip it and get the data.tar.gz and open again and unzip its items into a folder in your pc. What you actually need is the "/usr/lib/apache2/modules/mod_mono.so" file which you have to copy into folder "/share/HDA_DATA/.qpkg/Optware/libexec" in your QNAP (copy can be performed easy through FileZilla SSH ftp client). The way to check it in order to identify that everything you have done was ok is the following: Add at the end of httpd.conf the line:
and restart your apache server and it will run successfully.
After that you have to install mono-apache-server2. This is the backend for mod_mono. It lets you run ASP.NET web applications via Apache. mod_mono will call mono-apache-server to parse and compile the aspx code. You can download this again from debian packages through link: http://packages.debian.org/sid/mono-apache-server2. Unzip it again with archive manager as you did it with mod-mono. Copy the files from the unzipped folder into the following locations (create any non existent folder):
You will need also another file called Mono.WebServer2.dll (and has to rely into folder gac/Mono.WebServer2/0.2.0.0__0738eb9f132ed756/) which is not provided into mono-apache-server2 distribution and does not exist in Mono project installation from ipkg. I took it from my Ubuntu Mono project installation. (tip: don't forget to get also the symb link from mono/2.0/ folder for Mono.WebServer2.dll).
Another thing you must fix is the location of mono project that "/share/HDA_DATA/.qpkg/mono/usr/bin/mod-mono-server2" uses. Open this file and edit its contents as follows:
If you want to execute your mono application with Code Access Security (CAS) (this is disabled by default) you have to execute your application with --security option. so you may create another mono starter eg. script /share/HDA_DATA/.qpkg/mono/usr/bin/mod-mono-server2_Secure with content as follows:
Make also this file executable with the command:
And by restarting your apache everything will be fine.
Now you have to fix also the issues with the configuration files. You can get and put the configuration files got from mod-mono and mono-apache, into folder: "/share/HDA_DATA/.qpkg/Optware/etc/apache2/extra" and configure them properly into httpd.conf (http://go-mono.com/config-mod-mono/). However, i will give you a small-fast but messy configuration in order to test it.
You can also Use QNAP MySQL as Database server for you mono application. If you have already used before LinqToSQL in your .Net Project (with MSSQL server) there is an equivalent project named DBLinq (http://code.google.com/p/dblinq2007/). If you download it you can use it like sqlmetal in visual studio and you can create the Linq to MySQL classes and use them instead of LinqToSQL. Try the command (http://code.google.com/p/dblinq2007/wiki/DbMetal):
Then with the created cs you can use it into your .Net Project and this will provide you the necessary code for LinqToMySQL entities. However because of some problems-bugs of this project, you have to change all the private methods, properties and fields to public in the created cs (http://code.google.com/p/dblinq2007/iss ... ail?id=156). You May need also to create a non arg constructor as LinqToMSSql Server has (in order to minimize changes in your code):
You have also to remove the DBName from the "Table" attributes in this cs if your Database name is been taken dynamically.
Don't forget to use in you project the DbLinq.dll and DbLinq.MySql.dll and MySql.Data.dll(don't forget that if MySql.Data is installed in mono gac /share/HDA_DATA/.qpkg/mono/usr/lib/mono/gac/MySql.Data/ then it can be used from there and has to be absent from project directory. Take also care to have the same version).
The procedure you must follow is the following:
First of all you have to install Mono for QNAP (2.4.2.3) through a QPKG package (download it from here http://www.turbonas.com/phpBB3/viewtopic.php?f=18&t=942) and the upload it to qnap through QNAP administration console. The installation folder by QPKG will be: /share/HDA_DATA/.qpkg/mono.
Now you have to install through IPKG Apache2 (QNAP has pre installed Apache 1.3 as its web server but with this version its not simple to install mod-mono). Again into your NAS prompt the command:
Code: Select all
ipkg install apache
Code: Select all
User nobody
Group #-1
Here you must change these lines and put as user and group the guest so it will be:
Code: Select all
User guest
Group guest
After all you have to restart your new apache2 web server and everything will be ok on your NAS by the command:
Code: Select all
/share/HDA_DATA/.qpkg/Optware/sbin/apachectl restart
One usefull configuration in "httpd.conf" is to configure an error file to write inside in order to know whether Apache started or not. use a local file in your NAS disk such as:
Code: Select all
ErrorLog "/share/HDA_DATA/QBackup/tempo/error_log"
Code: Select all
LoadModule mono_module libexec/mod_mono.so
and restart your apache server and it will run successfully.
After that you have to install mono-apache-server2. This is the backend for mod_mono. It lets you run ASP.NET web applications via Apache. mod_mono will call mono-apache-server to parse and compile the aspx code. You can download this again from debian packages through link: http://packages.debian.org/sid/mono-apache-server2. Unzip it again with archive manager as you did it with mod-mono. Copy the files from the unzipped folder into the following locations (create any non existent folder):
Code: Select all
/etc/* => /share/HDA_DATA/.qpkg/mono/etc/*
/usr/* => /share/HDA_DATA/.qpkg/mono/usr/*
Another thing you must fix is the location of mono project that "/share/HDA_DATA/.qpkg/mono/usr/bin/mod-mono-server2" uses. Open this file and edit its contents as follows:
Code: Select all
#!/bin/sh
#exec /usr/bin/mono $MONO_OPTIONS "/usr/lib/mono/2.0/mod-mono-server2.exe" "$@"
exec /share/HDA_DATA/.qpkg/mono/usr/bin/mono $MONO_OPTIONS "/share/HDA_DATA/.qpkg/mono/usr/lib/mono/2.0/mod-mono-server2.exe" "$@"
Code: Select all
#!/bin/sh
exec /usr/local/mono/bin/mono --security /usr/local/mono/lib/mono/2.0/mod-mono-server2.exe "$@"
Code: Select all
chmod +x /share/HDA_DATA/.qpkg/mono/usr/bin/mod-mono-server2
And by restarting your apache everything will be fine.
Now you have to fix also the issues with the configuration files. You can get and put the configuration files got from mod-mono and mono-apache, into folder: "/share/HDA_DATA/.qpkg/Optware/etc/apache2/extra" and configure them properly into httpd.conf (http://go-mono.com/config-mod-mono/). However, i will give you a small-fast but messy configuration in order to test it.
Code: Select all
#Generic Code
<IfModule mod_mono.c>
MonoUnixSocket default /opt/tmp/.mod_mono_server2
MonoServerPath default /share/HDA_DATA/.qpkg/mono/usr/bin/mod-mono-server2
AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
MonoApplicationsConfigDir default /share/HDA_DATA/.qpkg/mono/etc/mono-server2
MonoPath default /share/HDA_DATA/.qpkg/mono/usr/lib/mono/2.0:/usr/lib
</IfModule>
#End Of generic code
AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
DirectoryIndex index.aspx
# Here it says that path for Mono Server will be the "/share/HDA_DATA/.qpkg/Optware/bin/mod-mono-server2" and will serve for "mynewsite" application
MonoServerPath mynewsite "/share/HDA_DATA/.qpkg/mono/usr/bin/mod-mono-server2"
# and for Secure: MonoServerPath mynewsite "/share/HDA_DATA/.qpkg/mono/usr/bin/mod-mono-server2_Secure"
# this is the path that my application by name "mynewsite" relies:
MonoApplications mynewsite "/mynewsite:/share/HDA_DATA/QBackup/tempo"
# Here we define the path for mono project where it is into our system
MonoPath mynewsite /share/HDA_DATA/.qpkg/mono/usr/lib/mono/2.0
# and provide an alias to the web server what user should put in browser is http://MyNasAddress:8888/mynewsite/
# /share/HDA_DATA/QBackup/tempo/ is the application physical path
Alias /mynewsite "/share/HDA_DATA/QBackup/tempo/"
<Location "/mynewsite">
Allow from all
Order allow,deny
MonoSetServerAlias mynewsite
# here we say that this site will be handled from mono
SetHandler mono
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
</Location>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
</IfModule>
Code: Select all
"E:\tmp\DbLinq-0.20.1\>
DbMetal.exe --u=testuser --password=testuser --server=MyNasServerAddress --database=MyDBName --provider=MySql --pluralize --namespace=DataConnectivity --case=leave --language=C# --code="E:\tmp\DbLinq-0.20.1\DataConnectivity.cs"
Code: Select all
public MyDBName(): this (new MySqlConnection(ConfigurationManager.AppSettings[@"MySqlConnectionString"].ToString()))
{
this.OnCreated();
}
Don't forget to use in you project the DbLinq.dll and DbLinq.MySql.dll and MySql.Data.dll(don't forget that if MySql.Data is installed in mono gac /share/HDA_DATA/.qpkg/mono/usr/lib/mono/gac/MySql.Data/ then it can be used from there and has to be absent from project directory. Take also care to have the same version).