Monday, December 6, 2010

Asp.Net Under Suse Linux Sample Example

/srv/www/htdocs - is your web root.
/usr/share/mono/asp.net/apps – Mono sample applications and starter kits.
/etc/apache2/conf.d - place where Apache is looking for configuration files.
/etc/xsp/2.0/applications-available – Mono configuration files.
First things first – in Windows file explorer select blog engine web project (I renamed it to be131) and drag it into VMware straight to the web root (/srv/www/htdocs). Set write permission on App_Data folder – right click it and set permissions almost like you would in Windows. If you run into problem - let everybody do anything on that folder. This is what sandboxes for :) You might think you are ready to go straight to the browser, but that won’t work (it would be way too easy). You need to tell Apache and Mono about new application they have to take care of.
In Apache, unlike IIS, you don’t have UI to set applications, virtual directories etc. Again, that would be too easy and no fun at all. Instead, you have configuration files and text editor. Let’s go ahead and edit those files. You’ll need to use root (admin) account. Start terminal window and type in “su root”, hit enter and, when prompted, “mono” as a password. Congratulations – you’ve just been promoted to almighty “root”. Now you can run any application from command line as administrator. Start text editor by typing “gedit” followed by file name you want to open. If file does not exist, Linux will create one for you.
>gedit /etc/apache2/conf.d/be131.conf
We need a new configuration file to tell apache where to find our application. We want it to look at physical directory “/srv/www/htdocs/be131” and map it to virtual path “/be131”, so that we can type “http://localhost/be131” to get to the site. Because Apache is going to use Mono module to run application, we need to supply a path to Mono configuration file and tell what .NET version to use (mod-mono-server2 for ASP.NET 2.0).
Copy and paste into the editor:
// /etc/apache2/conf.d/be131.conf
Alias /be131 /srv/www/htdocs/be131
MonoApplicationsConfigFile be131 /etc/xsp/2.0/applications-available/be131.webapp
MonoServerPath be131 "/usr/bin/mod-mono-server2"
MonoSetEnv be131 MONO_IOMAP=all

Allow from all
Order allow,deny
SetHandler mono
MonoSetServerAlias be131

Save file and close editor window. Now create another configuration file that will ask Mono to take care about our application:
>gedit /etc/xsp/2.0/applications-available/be131.webapp
Mono also needs to know physical and virtual path to the application to work properly.
// /etc/xsp/2.0/applications-available/be131.webapp


be131
/be131
/srv/www/htdocs/be131
true

Save. Close. Having fun yet? Almost there, all we need to do is to restart Apache:
> rcapache2 restart
Now you can open browser and navigate to http://localhost/be131 - and you will be greeted with usual “welcome to BlogEngine” page.

Wasn’t all that hard, wasn’t it? Well, to be honest it is because image we used already had all hard work done for us – installing Apache and Mono and configuring them to play together nicely. This is probably the easiest way to get your feet wet with Mono and ASP.NET in general, not just BlogEngine. If you know better way or have some interesting input or run into a problem – don’t hesitate to leave a message.

No comments:

Post a Comment