smithvoice.com
 Y'herd thisun? 

“In theory, theory and practice are the same. In practice, they are not.”
-Albert Einstein



MONO/Ubuntu part 7 - Installing Apache2 and MONO

TaggedLinux

Installing Apache2 and Mono

The part you've been waiting for... Making .Net apps and webapps work on Linux.

After the OS installation and update and firewalling, you'd think that this part would be super-hard, but with Ubuntu Server 8.10 it's actually very simple. You can install both Apache2 and a version of Mono that correctly does most all of .Net 2.0 and a good working segment of .Net 3.0 with just one multi-option command.

Linux should be named Caveatix... and that legal thing

Before we install Apache and Mono, we have to address some basics. Living in Linuxland where there are multiple kings and warlords isn't as simple as our parallel dimension where Microsoft-Is-The-One-True-God. Everything in non-Windows comes with at least one caveat and installable "best" versions depend on the direction of the wind.

Above we said "most of" and "good working segment" for the .Net features that a simple APT-GET will give your server. Mono, the cross platform .Net implementation project from Novell, hit version 2.2 back in January 2009. As you can see from the release notes the latest version includes a number of performance improvements, bug fixes and cool additional features (I really like the Mono.CSharp.Evaluator class, that lets you compile and execute C# code at runtime). *That* version of Mono, 2.2, is not yet officially available as an installable package set for Ubuntu variants. It *is* officially available for openSUSE because both Mono and openSUSE are from Novell, while Ubuntu is 'managed' by Canonical.

The Official version of Mono for Ubuntu Intrepid Ibex 8.10 (and desktop variants Ubuntu and Kubuntu 8.10) is 1.9.1 . In a nutshell, 1.9.1 gives you a full C#2.0 and 3.0 implementation and by default the C# compiler is set to 3.0 mode. 3.0's biggie was LINQ and you do get that at least with LINQ to Objects and LINQ to XML. Does "full" mean perfect? No, but neither did Microsoft's 2 and 3 releases. You will have to test test test to see if there are holes in the implementation that affect your needs directly. (Some I hit that you may not care about include: Datasets only serialize to diffgram even if you force the mode to WriteXMLSchema so you have to use external Schema files for Datasets you'll be traversing programatically, and the .Net 2.0 feature of cross-page postbacks does not work in 1.9.1, the syntax is accepted but the emitted clientside javascript call [formname]_DoPostBackWithOptions does not correctly pass a [formname]_PostBackOptions object, so you have to use a .Net1x style workaround such as a POST or session variable.)

Does this mean that you can't use the very latest and greatest Mono on your Ubuntu/Kubuntu? Nope, but getting that version installed isn't going to be as easy as installing the version that Canonical & the Ubuntu following considered most stable back at the time of the release of Ubuntu 8.10 at the end of October 2008. If you do attempt to upgrade to Mono 2.2, expect it to not be simple and assume the full responsibility of doing a LOT of testing before trusting it on an exposed system. Generally: Just as with any software, if you don't use the version deemed correct for your OS then you're on your own.


On mono-project.org they make it appear to be "very simple" to install from the Mono 2.2 source but in my experience - and I may just be really stupid - it's not "just" anything ;-0. Instead, I had better success on my Kubuntu 8.10/KDE4.2 machine by using the scripts wonderfully provided by DrScofield on xyzzyxyzzy.net.

For the happy record, though it won't be useful on your non-GUI Ubuntu servers, Mono 1.9.1 also was the first stable version to have real, useful System.Windows.Forms support. This is frikken killer. As of 1.9.1 you can take a Winforms app (exe and dlls and configs) that you made in VS2008 and just drop it on a Mac or Linux desktop box and call it with "mono myexe.exe" and it will load and run. Simply amazing. Honestly, not every exact little thing looks or works exactly the same such as docking not always settting itself correctly on a Mac when you resize, but it was so close in 1.9.1 that it blew me away. And, Mono 2.2 brought with it about 200 Winform fixes since 2.0 so once you're set with your server you really should play with making some cross-plat desktop apps.

Anyway, the bugs or differences in lower level implementation that I've found so far have only been niggles and the workarounds have easy to tackle. I think that you also will be very very happy with Mono 1.9.1 on Ubuntu server, for most non-extremely-top-secretly-mission-critical applications (meaning most all real-world applications that a working developer gets paid to make each year, even if they work for the NSA or NASA) it's going to do you very well and the combo will save your company money. BUT...

... that blown out of proportion caveat is here ... before pulling the trigger there is one Non-technical risk you should keep in the back of your mind. There is, thanks to the law being what it is, a slight legal risk. Slight, imho, but a risk to not ignore. Microsoft and Novell have a deal, MS won't sue Novell users for patent issues related to Mono. That is a deal between Microsoft and Novell, not between Microsoft and Canonical/Ubuntu.

There are a HUGE number of bloggy non-lawyers and FUDders and flat-out Redmond haters that blow that up way beyond what "Ballmer" might do and for what reasons. But these fine folks are like Zappa fans, you just can't please them. If Redmond created cold fusion and gave it away to ECMA those people would still prefer to wail at the moon, rend their garments, gnash their teeth and live in dark shacks. They ain't gonna ever let Microsoft or .Net or, now, even Novell have any slack at all.

I'm no lawyer either, but reading a lot of flames and grumbles and stuff from the horses has lead me to the impression that the issue isn't as drastic as is made out by the sad little boys who think it's still cool to refer to Microsoft as "M$". As my dear, smart and quite corporate biz-savy wife often says: "The truth is always somewhere in the middle." Problem is that the fuddites generally have no real lives - or the money it takes to get experience with the many good things from Microsoft - and their wanna-be noise skews the perception of the range.

If you want to be safest legally for the longest amount of time with .Net on Linux you might want to consider Novell's openSUSE for external client-facing commercial applications. openSUSE's not as simple as Ubuntu but if your boss is a conspiracy nut who believes in ghosts and Zeus and that everything will end in December 2012 then just make him happy. However, if you and your boss are more normal, if you prefer the simple yet powerful Ubuntu, if you understand that your .Net code will run the same by just dropping it over on some other mono-powered Linux - or Windows - whenever you want, and if you've been doing code long enough to realize that a cost-based OS decision on some boxes today does not chart the life of your company forever... then stick, at least till you get the gist of Linuxland, with Ubuntu.

Let us install

Connect to your Ubuntu server and do the deed:

sudo aptitude install apache2 mono-gmcs libapache2-mod-mono mono-apache-server2

There are a bunch of dependencies for Apache2 and Mono, punch "y" to accept and start the installation.

In a few seconds, after a line about starting the web server, the installation will appear to hang. It did, sort of. Apache2 is now running and that is holding up the works. But it's not a big deal. Just interrupt it with CTL-C and the install will continue.

Don't freak when you see a bunch of the failure lines, it's a verbose output. As each new dependency gets installed the script will try again and in the end it should fully recover and drop you at the commandline.

That's it. Apache is installed and running and Mono is installed and almost ready for you. Want proof? You'll need a browser.

Browsing the web in text mode

Obviously on a textual OS you're not going to get all kinds of multimedia browser support, but there's a nice CompuServe style browser that at least will give you something when you need to check stuff locally. It's called Lynx and it's just an apt-get away...

sudo aptitude install lynx

Once you have it just type its name, a space and the URL you want to show and up it comes.

lynx localhost

What you see is a default html file that got installed with Apache (more on that in a sec).

Open the Firewall for Apache

Lynx is cute and will be very helpful once you set asp.net errors to RemoteOnly, but you want an outsider test. First, you'll have to open up the firewall port 80. As we're using ufw, we'll call "ufw app list" to see that Apache added its general configurations to it's /etc/ufw/applications.d/ folder and then add the port 80 rule using the profile syntax. (For a refresher on all that ufw stuff, click here)

Now from off-box, call up the server's IP address.

Alright. To that "It works" page. When Apache installed it created a new folder at /var/www/ and in that new directory it put a file called "index.html". The "It works" is the text of that file, as you see when we call the "cat" command on it ("cat" does a concat of the text of the file and echos it to the commandline ).

If you open the file with nano and change it...

You'll see the change from a client...

Mono/.Net and ASP.Net execution

And what about the Mono installation? List the /usr/lib/folder and you should see a new directory named "mono" and if you list that directory you'll see your runtimes.

If you have a second, go back to Windows and use Visual Studio to create a little console exe.

Copy it over to your ubuntu home directory and start it via "mono [name of executable]", like:

Appears Mono is all set. But what of the ASP.Net.

Create a new web file, called test.htm and give it some html text.

sudo nano /var/www/test.htm

Test it in a browser. Ho Hum. Now to check that the multi-option installation set up MONO with Apache, registering the standard .Net file extensions. Just change test.html to test.aspx.

sudo mv test.htm test.aspx

The extension is handled by Apache, but is it really running serverside .Net code?

Back in the real world, open up Visual Studio and create a new Web site project. Delete the default webform (Default1.aspx) and add a new webform called monotest.aspx (all lower case is an important headache-reducing trick for Linux, get used to doing it). Add a button and a label...

 

(Sorry that's so scrunchy, I run VS to look good on 1680 screens so really had to squeeze it for this 700px panel)

Add a line to the button click event, I'm just going to put the current server time and web server account name in the label.

Use WinSCP to drag & drop the aspx and cs file over to your server's home directory, then PuTTY to move them to /var/www/

sudo mv monotest.* /var/www/

And call the aspx up in a browser....

ie7

ie8 (using custom hosts file)

Not exactly what we were looking for.

No, it's not because we used code-behinds, Mono and Apache work great on code behind files and master pages and on and on. We just need to do a little bit of configuration in Apache; just like we have to do in IIS but with text files instead of mouse clicks.


Coming next: After a quick hosts files setup, we'll get your Mono ASP.Net running fast and simple (and full featured), step by step.


jump to:

  • 1: Why?
  • 2: Installation
  • 3: Update the OS with APT
  • 4: Remoting to the box with SSH
  • 5: NANO quickies for 95% of the jobs
  • 6: Firewalling Ubuntu 8.10 Server
  • 7: Installing Apache2 and MONO
  • 8: Test client host files
  • 9: Configure MONO on Apache2
  • 10: Apache default pages
  • 11: Handling Apache and Mono Errors
  • 12: Subdomains and Christian porn
  • 13: Virtual Host Tweak: unmanaged cAse sensitiviTy
  • 14: Managed cAse sensitiviTy
  • 15: Managing files and folders
  • 16: Logging Apache Accesses and Errors
  • 17: Ubuntu Task Managers
  • 18: Ubuntu Services and Service Managers
  • 19: Installing Oracle 10g XE Server
  • 20: Connecting Mono to Oracle


  • home     who is smith    contact smith     rss feed π
    Since 1997 a place for my stuff, and it if helps you too then all the better smithvoice.com