Apache with MONO

Top of Form

http://www.smithvoice.com/apache-logging-access-and-errors

Build ASP.NET/Mono Applications with mod_mono and Apache on Ubuntu 12.04

Published: Thursday, August 5th, 2010 by Brett Kaplan

mod_mono is an Apache module that makes it possible to run ASP.NET applications in Linux environments running Apache. While ASP.NET is a Microsoft technology and is traditionally used with IIS, mod_monohas become a viable option for deploying ASP.NET applications on Linux. This guide is largely based on the mod_mono guide from the Ubuntu Community and theMono Project's Apache and Mono documentwith minor modifications. This guide does not cover installation and configuration of the Mono IDE which is used to develop ASP.NET applications on Linux. If you are interested in developing using Visual Studio for Mono, you can download a 30-day trial of the commercial Mono Tools plugin at the Mono Tools for Visual Studio page.

This guide assumes that you've followed the steps outlined in ourgetting started guide. You will install theApache web serverwith very minimal configuration. If you already have Apache installed and configured, you may omit these steps; however, if you have not installed Apache and are unfamiliar with this server read the installation guide for additional documentation. Additionally,mod_mono is incompatible with the integrated PHP interpreter described in other guides. If you need to have both mod_mono and PHP running on the same Apache server you will need to run PHP scripts using the CGI method

Contents


Enable Universe Repositories

Before installing mod_mono we must ensure that the universerepositories are enabled on your system. Your/etc/apt/sources.list should resemble the following (you may have to uncomment or add the universe lines):

File: sudo vi /etc/apt/sources.list

### DAQ

## main & restricted repositories

deb http://us.archive.ubuntu.com/ubuntu/ lucid main restricted

deb-src http://us.archive.ubuntu.com/ubuntu/ lucid main restricted

deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates main restricted

deb-src http://us.archive.ubuntu.com/ubuntu/ lucid main restricted

deb http://security.ubuntu.com/ubuntu lucid-security main restricted

deb-src http://security.ubuntu.com/ubuntu lucid-security main restricted

## universe repositories

deb http://us.archive.ubuntu.com/ubuntu/ lucid universe

deb-src http://us.archive.ubuntu.com/ubuntu/ lucid universe

deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe

deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe

deb http://security.ubuntu.com/ubuntu lucid-security universe

deb-src http://security.ubuntu.com/ubuntu lucid-security universe

If you had to enable new repositories, issue the following command to update your package lists:

#apt-get update

sudo aptitude update

aptitude (to see what remains)

#apt-get upgrade

sudo aptitude safe-upgrade

aptitude (to see what remains)

Install Apache

If you already have Apache installed and configured, you can safely skip this section of the guide. Install Apache by running the following command:

sudo apt-get install apache2

As mentioned earlier, you will need to go to the installation guide if you wish to configure your server beyond the default configuration.

Install mod_mono

The Apache daemon must be stopped before mod_mono is installed. Issue the following command to stop the apache process:

sudo /etc/init.d/apache2 stop

At this point we're able to install the required packages for mod_mono. Run the following command:

sudo apt-get install mono-apache-server2 libapache2-mod-mono libmono-i18n2.0-cil

While installing, you will see a prompt that looks like the following:

Configuration file `/etc/apache2/mods-available/mod_mono.conf'

==> File on system created by you or by a script.

==> File also in package provided by package maintainer.

What would you like to do about it ? Your options are:

Y or I : install the package maintainer's version

N or O : keep your currently-installed version

D : show the differences between the versions

Z : background this process to examine the situation

The default action is to keep your current version.

*** mod_mono.conf (Y/I/N/O/D/Z) [default=N] ?

Accept the default option at this point. When the installation process completes start Apache with the following command:

sudo vi /etc/apache2/apache2.conf

ErrorLog /srv/www-logs/apache2.error.log

sudo mkdir -p /srv/www-logs

sudo mkdir -p /srv/www

sudo useradd -d /home/apache -m apache

sudo passwd apache

sudo mkdir /home/apache/.mono

sudo chown root:apache /home/apache/.mono

sudo chmod 0774 /home/apache/.mono

sudo chown root:apache /srv/www-logs/

sudo chmod 0774 /srv/www-logs/

sudo chown -R apache /srv/www/

sudo chgrp -R apache /srv/www/

sudo chmod -R 0774 /srv/www/

sudo vi /etc/apache2/envvars

export APACHE_RUN_USER= apache
export APACHE_RUN_GROUP= apache

Configure Apache

We recommend using name-based virtual hosts for web hosting. Refer to the Apache documentation for setting up Name-based virtual hosts.

Recent versions of mod_mono utilize the AutoHosting method of application deployment. This allows non-privileged users to deploy new applications without modifying Apache configuration files. While this provides great flexibility, it may also present a security risk. As a result, mod_mono must be enabled on a per-virtual host basis.

For the sake of this guide, we're going to create a site on the root of our example domain, example.org. If you already have an Apache configuration for the root of your site, you will need to modify your existing virtual host file or create a new one on a subdomain of your site. Create the virtual host file, taking the following example virtual host configuration and modifying it to suit your needs. You may also use the Mod_Mono Configuration Generator to generate your own custom configuration.

File excerpt:/etc/apache2/sites-available/example.org

<VirtualHost *:80>

ServerName example.org

ServerAdmin web-admin@example.org

ServerAlias www.example.org

DocumentRoot /srv/www/example.org/public_html

ErrorLog /srv/www/example.org/logs/error.log

CustomLog /srv/www/example.org/logs/access.log combined

MonoServerPath example.org "/usr/bin/mod-mono-server2"

MonoDebug example.org true

MonoSetEnv example.org MONO_IOMAP=all

MonoApplications example.org "/:/srv/www/example.org/public_html"

<Location "/">

Allow from all

Order allow,deny

MonoSetServerAlias example.org

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>

Save and close the file, and create the directories referenced in theDocumentRoot and ErrorLog directive:

mkdir -p /srv/www/example.org/public_html

mkdir /srv/www/example.org/logs

Enable the site by running the a2ensite command:

a2ensite example.org

FileZilla Copy all files/directorys E:\WebSites\.NET WWW\* /home/apache/www

sudo mv /home/apache/www/*.com /etc/apache2/sites-available/

sudo mv /home/apache/www/*.Web /etc/apache2/sites-available/

sudo mv /home/apache/www/*.org /etc/apache2/sites-available/

sudo chown root:root /etc/apache2/sites-available/*

sudo mv /home/apache/www/complete/* /srv/www/

sudo –rf rm /home/apache/www/

sudo /etc/apache2/sites-available

sudo a2ensite AJ.QBytesWorld.com

sudo a2ensite Ashleigh.QBytesWorld.com

sudo a2ensite BlogEngine.Web

sudo a2ensite Gaming.BlogEngine.Web

sudo a2ensite Java.Qbytesworld.com

Agile.QBytesWorld.com

Ajax.QBytesWorld.com

QbytesWorld.com

QbytesWorld.DynDns.info

QbytesWorld.info

TFSBasicTraining.QBytesWorld.com

_bandrplus.com

sudo chown -R apache /srv/www/

sudo chgrp -R apache /srv/www/

sudo chmod -R 0774 /srv/www/

Since we have modified the virtual host configuration, Apache must be reloaded:

/etc/init.d/apache2 reload

If you still see the default "It works!" Apache installation page, you may need to disable the default site. Run the following command if this is an issue for you:

a2dissite default

/etc/init.d/apache2 reload

Note: Should you restart Apache in the future, you will see an error that will look similar to this:

[crit] (13)Permission denied: Failed to attach to existing dashboard,

and removing dashboard file '/tmp/mod_mono_dashboard_XXGLOBAL_1' failed

(Operation not permitted). Further action impossible.

You can safely ignore this warning, as it won't affect deployment using the methods explained in this guide.

Ubuntu Linux: add a new user to secondary group

Use the following syntax:

useradd -G Group-name Username
passwd Username

Create a group called foo and add user tom to a secondary group called foo:
$ sudo groupadd foo
$ sudo useradd -G foo tom

OR
# groupadd foo
# useradd -G foo tom

Verify new settings:


id tom
groups tom

Finally, set the password for tom user, enter:
$ sudo passwd tom
OR
# passwd tom
You can add user tom to multiple groups – foo, bar, and ftp, enter:
# useradd -G foo,bar,ftp top

useradd -d /home/apache -m apache

passwd apache

mkdir /home/apache/.mono

chown root:apache /home/apache/.mono

chmod 0774 /home/apache/.mono

chown root:apache /srv/www-logs/

chmod 0774 /srv/www-logs/

groupadd apache

useradd –g apache apache

sudo chown -R apache /srv/www/

sudo chgrp -R apache /srv/www/

sudo chmod -R 0774 /srv/www/

#########################################################

### Configure the rights to YourFolder ### (optional***)

cd /srv/www/YourFolder

sudo chown -R root:www-data .

sudo chmod -R 774 .

sudo usermod -a -G www-data <yourusername>

#########################################################

cat /etc/apache2/envvars

change ENVARS user and group:

vi /etc/apache2/envvars

export APACHE_RUN_USER= apache
export APACHE_RUN_GROUP= apache

sudo /etc/init.d/apache2 stop

rm -rf /tmp/.wapi/

sudo rm -rf /tmp/*

sudo rm -rf /srv/www-logs/*

sudo /etc/init.d/apache2 start

sudo /etc/init.d/apache2 start

sudo /etc/init.d/apache2 stop

sudo chmod -R 0777 /srv/

sudo chown -R www-data /srv/

sudo chgrp -R www-data /srv/

sudo rm -rf /tmp/*

sudo rm -rf /srv/www-logs/*

sudo /etc/init.d/apache2 start


You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.


Tag Cloud