Tuesday, August 31, 2010

How to install BlogEngine.NET on Linux?

I will try to explain how to install BlogEngine.NET in open-source environment. We will use Ubuntu 10.04 and Apache with mod_mono.

Let's start with installing required packages. (every command you should execute as a root!) 

$ apt-get install apache2 libapache2-mod-mono mono-apache-server2 asp.net2-examples

After installation mod_mono should be enabled in Apache by default. Check if there is a symlink to mod_mono.conf and mod_mono.load in /etc/apache2/mods-enabled.

Now run the server and check if mod_mono is configured properly:

$ apache2ctl start

If there are no errors, open your webbrowser and check http://localhost/samples address. You should see some asp.net examples provided by Mono. If it doesn't work, read error_log and check your mod_mono configuration file (/etc/apache2/mods-enabled/mod_mono.conf).

Now download the latest version of BlogEngine.NET from http://blogengine.codeplex.com/ . We're using version 1.6.1. Let's do some console dance!

Copy downloaded package to your server's document root directory (/var/www by default). 

$ cp BlogEngine.NET\ 1.6.1\ \(web\).zip /var/www/
$ cd /var/www


Decompress files: 

$ unzip BlogEngine.NET\ 1.6.1\ \(web\).zip

And move them to blog/ directory: 

$ mkdir blog
$ mv BlogEngine.Web/* blog/

$ cd blog/

We should also create App_Data/files directory for images and files which would be uploaded with our entries and pages: 

$ mkdir App_Data/files

Otherwise, while uploading files, we will get an error like: 

Message : Access to the path "/var/www/blog/App_Data/files" is denied

The App_Data directory should have write permissions (only for Apache): 

$ chgrp -R www-data App_Data/
$ chmod -R g+w App_Data/

Now we will add our application to Apache. We can use Apache mod_mono configuration tool - http://go-mono.com/config-mod-mono/ . As I'm not using Apache on my Desktop, I can configure server to host only BlogEngine.NET. This is my configuration (/etc/apache2/sites-available/default):
<VirtualHost *:80>
  ServerName localhost
  ServerAdmin web-admin@localhost
  DocumentRoot /var/www/blog
  # MonoServerPath can be changed to specify which version of ASP.NET is hosted
  # mod-mono-server1 = ASP.NET 1.1 / mod-mono-server2 = ASP.NET 2.0
  # For SUSE Linux Enterprise Mono Extension, uncomment the line below:
  # MonoServerPath localhost "/opt/novell/mono/bin/mod-mono-server2"
  # For Mono on openSUSE, uncomment the line below instead:
  MonoServerPath localhost "/usr/bin/mod-mono-server2"

  # To obtain line numbers in stack traces you need to do two things:
  # 1) Enable Debug code generation in your page by using the Debug="true"
  #    page directive, or by setting <compilation debug="true" /> in the
  #    application's Web.config
  # 2) Uncomment the MonoDebug true directive below to enable mod_mono debugging
  MonoDebug localhost true
 
  # The MONO_IOMAP environment variable can be configured to provide platform abstraction
  # for file access in Linux.  Valid values for MONO_IOMAP are:
  #    case
  #    drive
  #    all
  # Uncomment the line below to alter file access behavior for the configured application
  MonoSetEnv localhost MONO_IOMAP=all
  #
  # Additional environtment variables can be set for this server instance using
  # the MonoSetEnv directive.  MonoSetEnv takes a string of 'name=value' pairs
  # separated by semicolons.  For instance, to enable platform abstraction *and*
  # use Mono's old regular expression interpreter (which is slower, but has a
  # shorter setup time), uncomment the line below instead:
  # MonoSetEnv localhost MONO_IOMAP=all;MONO_OLD_RX=1

  MonoApplications localhost "/:/var/www/blog"
  <Location "/">
    Allow from all
    Order allow,deny
    MonoSetServerAlias localhost
    SetHandler mono
    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
  </Location>
  <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
  </IfModule>
</VirtualHost>

This is the end! Restart Apache:

$ apache2ctl restart

And go to the http://localhost . Yes, that's it! Your new BlogEngine.NET installation, it's working! The default user and password is admin:admin . Remember to change it as soon as possible!

I'm back again!

Hello everybody once again! Today I wanted to reactivate my blog and I realised that Blogger doesn't support FTP publishing since May, so I decided to create new one instead of migrating back to Google's servers. I want to place here some useful tips & tricks (mini articles and tutorials) for programmers and sys-admins. That's enough for a 'hello world' post. Back to work...