FreeBSD 9.0上架设apache支持.net aspx网页

1.    更新Freebsd
# freebsd-update fetch
# freebsd-update install
1.    更新ports tree源路径
# portsnap fetch extract

1.    更新ports tree
# cd /usr
# rehash
# csup -L 2 ports-supfiles

1.    更新Ports的索引文件
# cd /usr/ports ; make fetchindex

1.    确认系统已安装以下程序或服务器
libtool 2.4.x
gcc 4.6.x
perl-5.12.4_3
Apache server
Webmin server

确认方法:
# pkg_info | grep webmin
出现已下讯息则表示已安装
webmin-1.590_1       Web-based interface for system administration for Unix

1.    在mono project的网站有关于在FreeBSD上使用Mono的介绍:http://www.mono-project.com/Mono:FreeBSD
其中说到了获取mono的两种方式:FreeBSD ports tree 和 BSD# ports tree,同样BSD# ports tree中也包括了BSD# project的两个版本:稳定版本 mono  和开发版本 mono-devel

可以通过BSD#的ports tree合并工具mono-merge把BSD# prots tree合并到本地的FreeBSD ports tree中:

1.    BSD#估计采用了subversion进行源码管理,需要先安装subversion:
安装subversion
# cd /usr/ports/devel/subversion ;; make install clean

如果安装subversion过程中提如下提示:
You should build `devel/apr’ with db4 support to use subversion with it.
Please rebuild `devel/apr’ with option `’ and try again.
Or you can disable db4 support. Only ‘fs’ repository backend will be available.
To disable db4 support, define WITHOUT_BDB.

则重新安装配置一下apr,启用apr for BDB,再重新安装subversion即可:
# cd /usr/ports/devel/apr
1.    make config #启用apr for DBD
2.    make install FORCE_PKG_REGISTER=”yes”

1.    安装mono-merge
# cd /tmp
# wget http://bsd-sharp.googlecode.com/files/mono-merge.tar.gz
# tar zxvf mono-merge.tar.gz
# cd mono-merge
# make install
# cd .. ; rm -R mono-merge ; rm mono-gerge.tar.gz

1.    合并BSD# ports tree
合并稳定版ports tree:
# mono-merge

合并开发版ports tree:
# mono-merge -D

如果没有安装subversion,执行mono-merge时会提示错误:
# mono-merge
===> Checking out the FreeBSD-ports module.
svn: not found
Failed to check out the BSD# ports tree.

10.安装.Net所需的Freamwork Mono程序,须依序安装,否则会遇到X11错误:
# cd /usr/ports/x11-toolkits/gtk20
# make -DWITHOUT_X11 install clean

ports tree合并完成后,进入/usr/ports/lang/mono目录,安装mono最新版本。
# cd /usr/ports/lang/mono ;; make install clean

安装完成后执行# mono -V可以看到已经是mono 2.11.1。
# mono -V
Mono JIT compiler version 2.11.1 (tarball Mon Aug 27 14:47:06 CST 2012)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS:           normal
SIGSEGV:       normal
Notification: kqueue
Architecture: amd64
Disabled:     none
Misc:         softdebug
LLVM:         supported, not enabled.
GC:           Included Boehm (with typed GC and Parallel Mark)

# cd /usr/ports/lang/mono-basic ;; make install clean

# cd /usr/ports/devel/mono-addins ;; make install clean

# cd /usr/ports/devel/mono-tools ;; make install clean

11.安装Apache2需要加载的Mod-Mono模块
# cd /usr/ports/www/mod_mono ; make install clean

12.安装.net framework所需的libraries
# cd /usr/ports/x11-toolkits/libgdiplus ;; make BATCH=yes install clean

13.修改mod_mono.conf
# vi /usr/local/etc/apache22/Includes/mod_mono.conf
加入以下设定
<IfModule !mod_mono.c>
LoadModule mono_module /usr/local/libexec/apache22/mod_mono.so
MonoAutoApplication enabled
ForceType application/x-asp-net
MonoServerPath = /usr/local/bin/mod-mono-server4
</IfModule>

14.测试.net网页是否可执行
将mono的测试网页拷贝到自己的网页目录中
# cp -fR /usr/local/lib/xsp/test /usr/web

重新启动apache
# /usr/local/etc/rc.d/apache22 restart

使用浏览器查看网页服务器是否正常动作,若有网页出现表示可正常加载asp网页
以浏览器开启网页http://192.168.1.21/test/