linux上支持.NET,一次艰难的配置mono过程

由于有ASP.NET的页面要放到linux上面,这还满新鲜的,以前没搞过,说是要装mono.装起来没想到这么麻烦,用了一天半的时间.以下就是整个过程,其中很大的篇幅是失败时的调试信息,很希望谁能帮我分析一下

环境:
redhat9,apache2,mysql5,php5
已经配了PHP环境,并能正常工作.

安装过程:
保险起见,安装过程中停掉了apache,mysql,所装版本是1.2.4,用rpm安装
1.首先安装mono的rpm包
用rpm –vih *.rpm时停住不动,估计是要加—nodeps
所以用如下的顺序一个一个装
libgdiplus
mono-core
mono-data
mono-data-firebird
mono-data-oracle
mono-data-postgresql
mono-data-sqlite
mono-data-sybase
ibm-data-db2
mono-nunit
mono-locale-extras
rpm -ivh mono-web-1.2.4-3.novell.i586.rpm –nodeps
//这个和下面的winforms相互依赖,实在不行,所以加上了—nodeps参数
rpm -ivh mono-winforms-1.2.4-3.novell.i586.rpm
rpm -ivh mono-devel-1.2.4-3.novell.i586.rpm
rpm -ivh mono-extras-1.2.4-3.novell.i586.rpm
rpm -ivh mono-jscript-1.2.4-3.novell.i586.rpm
rpm -ivh mono-basic-1.2.4-0.novell.noarch.rpm
rpm -ivh bytefx-data-mysql-1.2.4-3.novell.i586.rpm
rpm -ivh mono-complete-1.2.4-3.novell.i586.rpm

2.然后装xsp/mod_mono
(下载页面http://www.go-mono.com/download-stable/redhat-9-i386上面并没有单独的mod_mono的rpm包下载,将这两个软件写在了一起)所以应该是包含在一起了
rpm -ivh xsp-1.2.4-0.novell.noarch.rpm
注:
rpm安装的XSP的目录结构
/usr/bin/xsp
/usr/lib/mono/gac/xsp
/usr/lib/xsp
/usr/share/doc/packages/xsp
rpm安装mono的目录结构
/etc/mono
/usr/bin/mono
/usr/lib/mono
/usr/share/mono-1.0/mono
/usr/include/mono-1.0/mono
/usr/lib/xsp/test测试目录

不知道如何修改httpd.conf,因为mod_mono的库文件不知道装哪了,找不到
所以改用源码安装mod_mono,修改了httpd.conf用IE访问测试页面报错
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
--------------------------------------------------------------------------------
Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7a mod_mono/1.2.4 PHP/5.0.4 Server at 192.168.0.111 Port 80
IE的标题栏显示503错误
没找到解决办法,此时参考到http://www.xiaojb.com/archives/it/mono.shtml里面写的” 第一次mono和xsp都放到了usr以外的地方,结果apache报503的临时错误。估计是路径的问题,重新编译后就好了。”

参考这篇文章采用源码安装,版本也用比较低的,恰好我的apache的安装路径和文章中的一样为/usr/local/apache2/,源码下载路径:http://go-mono.com/sources-maintenance/

1.首先安装libgdiplus-1.1.13.6,但是报错要装glib-2.4.0,装了glib以后make仍然报错
./configue正常,输出为:
……前面省略
cairo will be compiled with the following surface backends:
  Xlib: yes
  Quartz: no
  XCB: no
  Win32: no
  PostScript: no
  PDF: no
  glitz: no

the following font backends:
  FreeType: yes
  Win32: no
  ATSUI: no

and the following features:
  PNG functions: yes
---
Configuration summary

   * Installation prefix = /usr/local
   * Codecs supported:

      - TIFF: yes
      - JPEG: yes
      - GIF: yes
      - PNG: yes

      NOTE: if any of the above say 'no' you may install the
            corresponding development packages for them, rerun
            autogen.sh to include them in the build.

make报错信息为
……前面省略
n file included from ../cairo/src/cairo-ft.h:47,
                 from gdip.h:38,
                 from adjustablearrowcap.c:27:
/usr/include/ft2build.h:55:38: freetype/config/ftheader.h: No such file or directory
In file included from gdip.h:38,
                 from adjustablearrowcap.c:27:
../cairo/src/cairo-ft.h:48:10: #include expects "FILENAME" or <FILENAME>
In file included from gdip.h:38,
                 from adjustablearrowcap.c:27:
../cairo/src/cairo-ft.h:60: parse error before "face"
../cairo/src/cairo-ft.h:64: parse error before "cairo_ft_scaled_font_lock_face"
cc1: warnings being treated as errors
../cairo/src/cairo-ft.h:64: warning: type defaults to `int' in declaration of `cairo_ft_scaled_font_lock_face'
../cairo/src/cairo-ft.h:64: warning: data definition has no type or storage class
adjustablearrowcap.c: In function `gdip_adjust_arrowcap_clone_cap':
adjustablearrowcap.c:75: warning: implicit declaration of function `memcpy'
make[2]: *** [adjustablearrowcap.lo] Error 1
make[2]: Leaving directory `/home/yahoon/mono/libgdiplus-1.1.13.6/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/yahoon/mono/libgdiplus-1.1.13.6'
make: *** [all] Error 2
查了好像与freetype有关, libgdiplus包里面还有一个cairo文件夹,它的安装说明提示要装freetype-2.1.4但是用src.rpm装freetype-2.1.4提示要symlinks,源码装又报错…受不了放弃了.还是回头用rpm把这个libgdiplus装好(很奇怪这样安装整个过程没报错)

2.装mono
解压mono-1.1.13.8.2.tar.gz
然后到目录下执行
./configure --prefix=/usrmakemake install装这个要很长时间

3.装mod_mono
在其README里面写到”mod_mono is an apache module that provides ASP.NET functionality.” 知道它就是给提供ASP.NET支持的apche模块.
解压缩mod_mono-1.1.13.5.tar.gz
./configure --with-apxs=/usr/local/apache2/bin/apxs
make
make install

4.安装xsp
解压缩xsp-1.1.13.7.tar.gz
./configure --prefix=/usr
make
make install

按照那篇文章里面讲的,修改httpd.conf配置文件
cd /usr/local/apache2/conf
mod_mono.conf已经存在了,只需要包含到httpd.conf里边就可以了
httpd.conf中加入
Include /usr/local/apache2/conf/mod_mono.confAlias /test "/usr/lib/xsp/test"AddMonoApplications default  "/test:/usr/lib/xsp/test"     SetHandler mono    AllowOverride None    Order allow,denyAllow from all 检查语法是否有错
/usr/local/apache2/bin/apachectl configtest
这个地方报语法错误.最后我把后面三行都注释掉了
#    AllowOverride None
#    Order allow,deny
#    Allow from all

启动apache/usr/local/apache2/bin/apachectl start
打开IE进行测试,地址是http://服务器IP/test/index.aspx
会看到XSP的欢迎页面.

但是发现我原来的PHP不能访问了,打开时会弹出一个下载文件的对话框.
查看了mod_mono的INSTALL文件,修改httpd.conf时,需要在SetHandler子句前后加上一个判断,修改后为
Include /usr/local/apache2/conf/mod_mono.conf
Alias /test "/usr/lib/xsp/test"
AddMonoApplications default  "/test:/usr/lib/xsp/test"

<Location /test>
SetHandler mono
#    AllowOverride None
#    Order allow,deny
#    Allow from all
</Location>
这样就PHP和测试页面都正常了.

打开mod_mono.conf,看到里面的内容为,就知道mono支持的文件类型了.
<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
    DirectoryIndex index.aspx
    DirectoryIndex Default.aspx
    DirectoryIndex default.aspx
</IfModule>

将开发的源码文件放到/test:/usr/lib/xsp/test下,假设目录为/usr/lib/xsp/test/CLRate,其主页文件为Main.aspx,访问地址http://ip/test/CLRater/Main.aspx,奇怪的是此时报页面错误.没办法了,修改httpd.conf,将test虚拟目录直接指到这里
Include /usr/local/apache2/conf/mod_mono.conf
Alias /test "/usr/lib/xsp/test/CLRater"
AddMonoApplications default  "/test:/usr/lib/xsp/test/CLRater"

<Location /test>
SetHandler mono
#    AllowOverride None
#    Order allow,deny
#    Allow from all
</Location>
访问http://IP/test/Main.aspx正常显示
至于为什么报页面错误,还不知道是啥原因.

整个的安装过程就是这样,有点乱,因为是整个安装的过程确实比较”曲折”.其中很多的问题没解决.欢迎大家一起讨论,提出一些建议和方法.