How to configure Mono in Apache (QNAP TS-210)

Post your questions about Web Server usage and Apache + PHP + MySQL/SQLite web applications.
Post Reply
balco31
New here
Posts: 2
Joined: Mon May 10, 2010 5:05 pm

How to configure Mono in Apache (QNAP TS-210)

Post by balco31 »

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:

Code: Select all

ipkg install apache
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:

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
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:

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"
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:

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/*
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:

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" "$@"
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:

Code: Select all

#!/bin/sh
exec /usr/local/mono/bin/mono --security /usr/local/mono/lib/mono/2.0/mod-mono-server2.exe "$@"
Make also this file executable with the command:

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>

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):

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" 
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):

Code: Select all

        public MyDBName(): this (new MySqlConnection(ConfigurationManager.AppSettings[@"MySqlConnectionString"].ToString()))

        {

            this.OnCreated();

        }
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).
bungle
New here
Posts: 2
Joined: Sat May 21, 2011 11:42 pm

Re: How to configure Mono in Apache (QNAP TS-210)

Post by bungle »

Ive been trying to get aspx pages on my TS210 for weeks now. Tried everything including compiling from source but it seems the qnap is running a limited version of linux and this is the root of most of my problems. The furthest ive got is to see the following line in apache log:

** (/share/MD0_DATA/.qpkg/mono/usr/lib/mono/2.0/mod-mono-server2.exe:13386): WARNING **: Missing method Mono.WebServer.MonoWorkerRequest::set_CheckFileAccess(bool) in assembly /share/MD0_DATA/.qpkg/mono/usr/lib/mono/gac/Mono.WebServer2/0.2.0.0__0738eb9f132ed756/Mono.WebServer2.dll, referenced in assembly /share/MD0_DATA/.qpkg/mono/usr/lib/mono/2.0/mod-mono-server2.exe
Stacktrace:

can you please explain the step ..... tip: don't forget to get also the symb link from mono/2.0/ folder for Mono.WebServer2.dll). in more detail.

I copied mono.webserver2.dll from an xsp2.0 install folder and used gacutil to install it.

If you can help me out that would be appreciated - new to linux and mono :(
thanks
User avatar
schumaku
Guru
Posts: 43579
Joined: Mon Jan 21, 2008 4:41 pm
Location: Kloten (Zurich), Switzerland -- Skype: schumaku
Contact:

Re: How to configure Mono in Apache (QNAP TS-210)

Post by schumaku »

From the [Get QPKG] pop-up:

Description: Mono provides .NET Framework environment to run ASP-based websites on Linux.
Version: 2.6.1
Maintainer: QNAP Systems, Inc.
Resource: Forum Discussion | Official Wiki
Download: Intel x86 [TS-x39 series/ x59 Series/ 509/ 809/ 809U-RP/ SS-439/ 839/ x59 Pro+]

From the QPKG Mono forum:
<url=http://forum.qnap.com/viewtopic.php?f=214&t=31552>[QPKG] Mono v2.6.1 - Running your ASP.NET sites on the QNAP</url>

[Download]
Mono v2.6.1
x86 (Intel based) [TS-239/ 439/ 509/ 639/ 809/ 809U-RP/ 839/ SS-439/ 839]

Conclusion: Intel only as it looks ot me...
bungle
New here
Posts: 2
Joined: Sat May 21, 2011 11:42 pm

Re: How to configure Mono in Apache (QNAP TS-210)

Post by bungle »

As far as i understand the qpkg installs mono and mod_mono - for x86

http://wiki.qnap.com/wiki/Mono
"The current ARM version does not have yet the correct libgdiplus library to support Q-Sims."

but..
you can install mono 2.4 using.. ipkg install mono and it doesn't throw any errors?

http://forum.qnap.com/viewtopic.php?t=13651
"I tested it on my TS-410 (ARMx19) and it just works fine"
pasamo
First post
Posts: 1
Joined: Wed Feb 08, 2012 2:49 am

Re: How to configure Mono in Apache (QNAP TS-210)

Post by pasamo »

Firstly, I'd like to sincerely thank you this tutorial.

Then, I'll put you in the picture: I have a TS-110 appliance. I've been through all your directions clearly and without any errors.

But I went lost by the time I,ve looked for the "Mono.WebServer2.dll" file out there, and the "symb link", too.

Providing a download link of both files would be perfect. Otherwise, could you please explain in detail the way to preceed?

Many thanks in advance.

Pablo.
iqorek
New here
Posts: 6
Joined: Thu Sep 02, 2010 7:45 pm

Re: How to configure Mono in Apache (QNAP TS-210)

Post by iqorek »

Hi, i receive error 500 from server and no any record in log.
1. How to configure mod_mono log?
2. Can you share working files? /share/HDA_DATA/.qpkg/mono/* and mod_mono.so?

log:

Code: Select all

[Tue May 15 21:52:26 2012] [warn] child process 7787 still did not exit, sending a SIGTERM
[Tue May 15 21:52:26 2012] [warn] child process 7788 still did not exit, sending a SIGTERM
[Tue May 15 21:52:26 2012] [warn] child process 7789 still did not exit, sending a SIGTERM
[Tue May 15 21:52:27 2012] [debug] worker.c(1083): the listener thread didn't exit
[Tue May 15 21:52:27 2012] [debug] worker.c(1083): the listener thread didn't exit
[Tue May 15 21:52:27 2012] [debug] worker.c(1083): the listener thread didn't exit
[Tue May 15 21:52:28 2012] [notice] SIGHUP received.  Attempting to restart
[Tue May 15 21:52:29 2012] [notice] Digest: generating secret for digest authentication ...
[Tue May 15 21:52:29 2012] [notice] Digest: done
[Tue May 15 21:52:29 2012] [info] APR LDAP: Built with OpenLDAP LDAP SDK
[Tue May 15 21:52:29 2012] [info] LDAP: SSL support available
[Tue May 15 21:52:29 2012] [info] mod_unique_id: using ip addr 192.168.1.10
[Tue May 15 21:52:30 2012] [info] Init: Seeding PRNG with 136 bytes of entropy
[Tue May 15 21:52:30 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits)
[Tue May 15 21:52:30 2012] [info] Init: Generating temporary DH parameters (512/1024 bits)
[Tue May 15 21:52:30 2012] [info] Init: Initializing (virtual) servers for SSL
[Tue May 15 21:52:30 2012] [info] mod_ssl/2.2.20 compiled against Server: Apache/2.2.20, Library: OpenSSL/0.9.8p
[Tue May 15 21:52:30 2012] [notice] Apache/2.2.20 (Unix) mod_ssl/2.2.20 OpenSSL/0.9.8v DAV/2 mod_mono/2.4.2 configured -- resuming normal operations
[Tue May 15 21:52:30 2012] [info] Server built: Feb 14 2012 08:13:01
[Tue May 15 21:52:30 2012] [debug] worker.c(1757): AcceptMutex: sysvsem (default: sysvsem)
[Tue May 15 21:52:30 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 7898 for worker proxy:reverse
[Tue May 15 21:52:30 2012] [debug] proxy_util.c(1914): proxy: initialized worker 0 in child 7898 for (*) min=0 max=25 smax=25
[Tue May 15 21:52:30 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 7897 for worker proxy:reverse
[Tue May 15 21:52:30 2012] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 15 21:52:30 2012] [debug] proxy_util.c(1914): proxy: initialized worker 0 in child 7897 for (*) min=0 max=25 smax=25
[Tue May 15 21:52:30 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 7896 for worker proxy:reverse
[Tue May 15 21:52:30 2012] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Tue May 15 21:52:30 2012] [debug] proxy_util.c(1914): proxy: initialized worker 0 in child 7896 for (*) min=0 max=25 smax=25
Post Reply

Return to “Web Server & Applications (Apache + PHP + MySQL / SQLite)”