Serving ASP.NET on Apache with Mod Mono
In order to serve ASP.NET on Linux, we will use Apache with Mono. We will be going through the steps on how to set it up.
We will be using the following:
- Apache
- Mono, Mod-Mono
- LibGdiPlus
- XSP
Lets get started with our setup:
Install Dependencies:
$ yum install httpd httpd-devel bison gettext glib2 freetype fontconfig libpng libpng-devel libX11 libX11-devel glib2-devel libgdi* libexif glibc-devel urw-fonts java unzip gcc gcc-c++ automake autoconf libtool make bzip2 wget libungif-devel freetype-devel libtiff-devel libjpeg-devel xulrunner-devel perl-TimeDate.noarch expect libexif libexif-devel -y
Download Packages:
$ mkdir /root/mono; cd /root/mono
$ wget http://origin-download.mono-project.com/sources/mono-1.1.16/mono-3.4.0.tar.bz2
$ wget http://origin-download.mono-project.com/sources/xsp/xsp-2.10.2.tar.bz2
$ wget http://origin-download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.9.tar.bz2
$ wget http://origin-download.mono-project.com/sources/mod_mono/mod_mono-2.10.tar.bz2
$ tar xjf mono-3.4.0.tar.bz2
$ tar xjf xsp-2.10.2.tar.bz2
$ tar xjf libgdiplus-2.10.9.tar.bz2
$ tar xjf mod_mono-2.10.tar.bz2
Compile
MOD MONO:
$ cd ~/mono/mod_mono-2.10
$ ./configure --prefix=/usr
$ make
$ make install
$ ldconfig
LIBGDI:
$ cd ~/mono/libgdiplus-2.10.9
$ ./configure --prefix=/usr
$ make
$ make install
MONO:
$ cd ~/mono/mono-3.4.0
$ ./autogen.sh --prefix=/usr
$ perl -pi -e 's/HAVE_LOCALCHARSET_H 1/HAVE_LOCALCHARSET_H 0/' eglib/config.h
$ make -j 8
$ make install
ENV VARIABLES:
$ echo export $ PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH>>~/.bash_profile
$ echo export PATH=/usr/bin:$PATH>>~/.bash_profile
$ source ~/.bash_profile
XSP:
$ cd ~/mono/xsp-2.10.2
$ ./configure --prefix=/usr
$ export PKG_CONFIG_PATH=`whereis pkgconfig | awk '{print $2}'`
$ make
$ make install
Edit your httpd.conf
and append this at your NameVirtualHost section
Include /etc/httpd/conf/mod_mono.conf
NameVirtualHost *:80
Include /etc/httpd/conf/sites-enabled/
<VirtualHost *:80>
ServerName aspnet.ruanbekker.com
ServerAdmin ruan@ruanbekker.com
DocumentRoot /var/www/html/asp1
ErrorLog logs/asp-error_log
CustomLog logs/asp-access_log combined
</VirtualHost>
Create sites-enabled/asp.conf
$ vi /etc/httpd/sites-enabled/u1t.conf
ServerAdmin ruan@ruanbekker.com
DocumentRoot /var/www/html/asp1
DirectoryIndex Default.aspx
ServerName asp.ruanbekker.com
ServerPath /
MonoAutoApplication enabled
MonoApplications "/:/var/www/html/asp1"
MonoServerPath "/usr/bin/mod-mono-server2"
AddHandler mono .aspx .ascx .asax .ashx .config .cs .asmx .axd
ErrorLog /var/log/httpd/asp-error_log
CustomLog /var/log/httpd/asp-access_log common
Ensure that /etc/httpd/conf/mod_mono.conf
has the following content:
<IfModule !mod_mono.c>
LoadModule mono_module /usr/lib64/httpd/modules/mod_mono.so
</IfModule>
<IfModule mod_headers.c>
Header set X-Powered-By "Mono"
</IfModule>
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 .vb
AddType application/x-asp-net .master
AddType application/x-asp-net .sitemap
AddType application/x-asp-net .resources
AddType application/x-asp-net .skin
AddType application/x-asp-net .browser
AddType application/x-asp-net .webinfo
AddType application/x-asp-net .resx
AddType application/x-asp-net .licx
AddType application/x-asp-net .csproj
AddType application/x-asp-net .vbproj
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
Create /etc/httpd/conf.d/mono_setup.conf
:
$ vi /etc/httpd/conf.d/mono_setup.conf
Include /etc/httpd/conf/mod_mono.conf
MonoApplications "/:/var/www/html/clients/u1t"
MonoServerPath "/opt/mono-2.11.4/bin/mod-mono-server2"
Options FollowSymLinks
AddHandler mono .aspx .ascx .asax .ashx .config .cs .asmx .axd
Grant Permissions:
$ chown -R apache:apache /var/www/html/asp1
$ service httpd restart
Create Sample Page:
$ vi /var/www/html/asp1/Default.aspx
<html>
<body>
<% Response.Write("Hello World!"); %>
</body>
</html>
If your application will be using MySQL, download these and import them:
$ wget repo.ruanbekker.com/packages/mysql.data.dll
$ wget repo.ruanbekker.com/packages/mysql.web.dll
$ wget repo.ruanbekker.com/packages/mysql.visualstudio.dll
$ gacutil /i mysql.data.dll
$ gacutil /i mysql.visualstudio.dll
$ gacutil /i mysql.web.dll
You should now have a working setup.