﻿{"id":334,"date":"2010-10-29T09:11:38","date_gmt":"2010-10-29T01:11:38","guid":{"rendered":"http:\/\/nick.workao.org\/index.php\/dotnet\/334"},"modified":"2010-10-29T09:11:38","modified_gmt":"2010-10-29T01:11:38","slug":"build-asp-netmono-applications-with-mod_mono-and-apache-on-debian-5-lenny","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/win\/334","title":{"rendered":"Build ASP.NET\/Mono Applications with mod_mono and Apache on Debian 5 (Lenny)"},"content":{"rendered":"<p><tt>mod_mono<\/tt> 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, <tt>mod_mono<\/tt> has become a viable option for deploying ASP.NET applications on Linux.  This guide is inspired by the <a href=\"https:\/\/help.ubuntu.com\/community\/ModMono\">mod_mono guide created by the Ubuntu Community<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/> and the <a href=\"http:\/\/mono-project.com\/Mod_mono\">Mono Project&#8217;s Apache and Mono document<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/> with 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 <a href=\"http:\/\/go-mono.com\/monotools\">Mono Tools for Visual Studio page<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/>.<\/p>\n<p>This guide assumes that you&#8217;ve followed the steps outlined in our <a href=\"http:\/\/library.linode.com\/getting-started\/\">getting started guide<\/a>. You will install the <a href=\"http:\/\/library.linode.com\/web-servers\/apache\/installation\/debian-5-lenny\">Apache web server<\/a> with 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, <tt>mod_mono<\/tt> 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 <a href=\"http:\/\/library.linode.com\/web-servers\/apache\/php-cgi\/debian-5-lenny\">PHP scripts using the CGI method<\/a><\/p>\n<p>These instructions work with the Linode platform. If you don&#8217;t have a Linode yet, sign up for a <a title=\"Linode Linux VPS\" href=\"http:\/\/www.linode.com\/?r=f4ac5ae5f59e43a8b31de8077ceab27bd1e60c80\">Linux VPS<\/a> and get started today.<\/p>\n<div>\n<div>Contents<\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#install_required_software\">Install Required Software<\/a><\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#install_apache\">Install Apache<\/a><\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#install_mod_mono\">Install mod_mono<\/a><\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#configure_apache\">Configure Apache<\/a><\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#installing_mysql_connector_net_for_aspnet\">Installing MySQL Connector\/Net for ASP.NET<\/a><\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#creating_a_database_to_test_the_mysql_connector\">Creating a Database to Test the MySQL Connector<\/a><\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#creating_a_simple_aspnet_application\">Creating a Simple ASP.NET Application<\/a><\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#more_information\">More Information<\/a><\/div>\n<div><a href=\"http:\/\/library.linode.com\/development\/frameworks\/dot-net\/mod-mono\/debian-5-lenny#license\">License<\/a><\/div>\n<\/div>\n<div id=\"install-required-software\"><a name=\"install_required_software\"><\/a>\n<h2>Install Required Software\u00a0<a href=\"http:\/\/library.linode.com\/PHDWLH\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/link-icon.png\" alt=\"Link\"><\/a><\/h2>\nBefore beginning the installation process, issue the following command to update your package lists:\n<pre>apt-get update\napt-get upgrade\n<\/pre>\n<div id=\"install-apache\"><a name=\"install_apache\"><\/a>\n<h3>Install Apache\u00a0<a href=\"http:\/\/library.linode.com\/KYbDXP\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/link-icon.png\" alt=\"Link\"><\/a><\/h3>\nIf you already have Apache installed and configured, you can safely skip this section of the guide. Install Apache by running the following command:\n<pre>apt-get install apache2\n<\/pre>\nAs mentioned earlier, you will need to go to the installation guide if you wish to configure your server beyond the default configuration.\n\n<\/div>\n<div id=\"install-mod-mono\"><a name=\"install_mod_mono\"><\/a>\n<h3>Install mod_mono\u00a0<a href=\"http:\/\/library.linode.com\/LcQOot\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/link-icon.png\" alt=\"Link\"><\/a><\/h3>\nThe Apache daemon must be stopped before <tt>mod_mono<\/tt> is installed. Issue the following command to stop the apache process:\n<pre>\/etc\/init.d\/apache2 stop\n<\/pre>\nAt this point we&#8217;re able to install the required packages for <tt>mod_mono<\/tt>. Run the following command:\n<pre>apt-get install mono-apache-server2 libapache2-mod-mono libmono-i18n2.0-cil\n<\/pre>\nWhen the installation process completes start Apache with the following command:\n<pre>\/etc\/init.d\/apache2 start\n<\/pre>\n<\/div>\n<div id=\"configure-apache\"><a name=\"configure_apache\"><\/a>\n<h3>Configure Apache\u00a0<a href=\"http:\/\/library.linode.com\/bdozsy\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/link-icon.png\" alt=\"Link\"><\/a><\/h3>\nWe recommend using name-based virtual hosts for web hosting. Refer to the Apache documentation for <a href=\"http:\/\/library.linode.com\/web-servers\/apache\/installation\/debian-5-lenny#configure_apache_for_named_based_virtual_hosting\">setting up Name-based virtual hosts<\/a>.\n\nRecent versions of <tt>mod_mono<\/tt> utilize the <tt>AutoHosting<\/tt> 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, <tt>mod_mono<\/tt> must be enabled on a per-virtual host basis.\n\nFor the sake of this guide, we&#8217;re going to create a site on the root of our example domain, <tt>ducklington.org<\/tt>. 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 <a href=\"http:\/\/go-mono.com\/config-mod-mono\/\">Mod_Mono Configuration Generator<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\"> to generate your own custom configuration.\n\n<strong>File excerpt:<\/strong> <em>\/etc\/apache2\/sites-available\/ducklington.org<\/em>\n<div>\n<pre><VirtualHost *:80>\n  ServerName ducklington.org\n  ServerAdmin web-admin@ducklington.org\n  ServerAlias www.ducklington.org\n  DocumentRoot \/srv\/www\/ducklington.org\/public_html\n  ErrorLog \/srv\/www\/ducklington.org\/logs\/error.log\n  CustomLog \/srv\/www\/ducklington.org\/logs\/access.log combined\n\n  MonoServerPath ducklington.org \"\/usr\/bin\/mod-mono-server2\"\n  MonoDebug ducklington.org true\n  MonoSetEnv ducklington.org MONO_IOMAP=all\n  MonoApplications ducklington.org \"\/:\/srv\/www\/ducklington.org\/public_html\"\n  <Location \"\/\">\n    Allow from all\n    Order allow,deny\n    MonoSetServerAlias ducklington.org\n    SetHandler mono\n    SetOutputFilter DEFLATE\n    SetEnvIfNoCase Request_URI \"\\.(?:gif|jpe?g|png)$\" no-gzip dont-vary\n  <\/Location>\n  <IfModule mod_deflate.c>\n    AddOutputFilterByType DEFLATE text\/html text\/plain text\/xml text\/javascript\n  <\/IfModule>\n<\/VirtualHost>\n<\/pre>\n<\/div>\nSave and close the file, and create the directories referenced in the <tt>DocumentRoot<\/tt> and <tt>ErrorLog<\/tt> directive:\n<pre>mkdir -p \/srv\/www\/ducklington.org\/public_html\nmkdir \/srv\/www\/ducklington.org\/logs\n<\/pre>\nEnable the site by running the <tt>a2ensite<\/tt> command:\n<pre>a2ensite ducklington.org\n<\/pre>\nSince we have modified the virtual host configuration, Apache must be reloaded:\n<pre>\/etc\/init.d\/apache2 reload\n<\/pre>\nNote: Should you restart Apache in the future, you will see an error that will look similar to this:\n<pre>[crit] (13)Permission denied: Failed to attach to existing dashboard,\nand removing dashboard file '\/tmp\/mod_mono_dashboard_XXGLOBAL_1' failed\n(Operation not permitted). Further action impossible.\n<\/pre>\nYou can safely ignore this warning, as it won&#8217;t affect deployment using the methods explained in this guide.\n\n<\/div>\n<\/div>\n<div id=\"installing-mysql-connector-net-for-asp-net\"><a name=\"installing_mysql_connector_net_for_aspnet\"><\/a>\n<h2>Installing MySQL Connector\/Net for ASP.NET\u00a0<a href=\"http:\/\/library.linode.com\/btluzY\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/link-icon.png\" alt=\"Link\"><\/a><\/h2>\nThis section assumes that you already have a functioning MySQL installation. Please refer to our <a href=\"http:\/\/library.linode.com\/databases\/mysql\/debian-5-lenny\">MySQL Installation Guide<\/a> for more detailed instructions for installing MySQL, otherwise issue the following command:\n<pre>apt-get install mysql-server\n<\/pre>\nIn order for your ASP.NET application to communicate properly with your MySQL server, you must install the MySQL Connector\/Net driver. The following commands download and install the 6.2.3 version of the connector. Check the <a href=\"http:\/\/dev.mysql.com\/downloads\/connector\/net\/\">MySQL Upstream<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\"> to ensure that this the latest version of the plugin:\n<pre>cd \/opt\/\nwget http:\/\/dev.mysql.com\/get\/Downloads\/Connector-Net\/mysql-connector-net-6.2.3-noinstall.zip\/from\/http:\/\/mysql.mirrors.pair.com\/\nunzip -d mysqlConnector mysql-connector-net-6.2.3-noinstall.zip\ncd mysqlConnector\ngacutil -i mysql.data.dll\ngacutil -i mysql.web.dll\n<\/pre>\n<\/div>\n<div id=\"creating-a-database-to-test-the-mysql-connector\"><a name=\"creating_a_database_to_test_the_mysql_connector\"><\/a>\n<h2>Creating a Database to Test the MySQL Connector\u00a0<a href=\"http:\/\/library.linode.com\/cJMNAi\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/link-icon.png\" alt=\"Link\"><\/a><\/h2>\nNow that the MySQL Connector has been installed, you should test it by creating a sample database and a test table. First you must log in to your MySQL DBMS:\n<pre>mysql -u root -p\n<\/pre>\nNext you must create the sample table. Issue the following commands at the MySQL prompt:\n<pre>CREATE DATABASE sample;\nUSE sample;\nCREATE TABLE test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(25));\nINSERT INTO sample.test VALUES (null, 'Lucy');\nINSERT INTO sample.test VALUES (null, 'Ivan');\nINSERT INTO sample.test VALUES (null, 'Nicole');\nINSERT INTO sample.test VALUES (null, 'Ursula');\nINSERT INTO sample.test VALUES (null, 'Xavier');\n<\/pre>\nFinally you must create a test user named &#8220;testuser&#8221; and give that user access to the newly created sample database:\n<pre>CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'somepassword';\nGRANT ALL PRIVILEGES ON sample.* TO 'testuser'@'localhost';\nFLUSH PRIVILEGES;\n<\/pre>\n<\/div>\n<div id=\"creating-a-simple-asp-net-application\"><a name=\"creating_a_simple_aspnet_application\"><\/a>\n<h2>Creating a Simple ASP.NET Application\u00a0<a href=\"http:\/\/library.linode.com\/oOBmrP\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/link-icon.png\" alt=\"Link\"><\/a><\/h2>\nNow that you have created a sample database, you can test your installation with the following test page. This will not only test your Mono installation but it will also will test your MySQL connector configuration. First create a file called <tt>testdb.aspx<\/tt> in your <tt>DocumentRoot<\/tt> and paste the text below into it.  Be sure to change the <tt>User ID<\/tt> and <tt>Password<\/tt> to match what you specified above.\n\n<strong>File excerpt:<\/strong> <em>\/srv\/www\/ducklington.org\/public_html\/testdb.aspx<\/em>\n\n[COLORIZE aspx-cs] <%@ Page Language=\"C#\" %> <%@ Import Namespace=\"System.Data\" %> <%@ Import Namespace=\"MySql.Data.MySqlClient\" %> <!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Strict\/\/EN\" \"<a href=\"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-strict.dtd\">http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-strict.dtd<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\">&#8220;> <html xmlns=\"<a href=\"http:\/\/www.w3.org\/1999\/xhtml\">http:\/\/www.w3.org\/1999\/xhtml<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\">&#8221; xml:lang=&#8221;en&#8221; lang=&#8221;en&#8221;> <head> <title>ASP and MySQL Test Page<\/title> <meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/>\n\n<script runat=\"server\"> private void Page_Load(Object sender, EventArgs e) { string connectionString = \"Server=127.0.0.1;Database=sample;User ID=testuser;Password=somepassword;Pooling=false;\"; MySqlConnection dbcon = new MySqlConnection(connectionString); dbcon.Open();\n\nMySqlDataAdapter adapter = new MySqlDataAdapter(\"SELECT * FROM test\", dbcon); DataSet ds = new DataSet(); adapter.Fill(ds, \"result\");\n\ndbcon.Close(); dbcon = null;\n\nSampleControl.DataSource = ds.Tables[\"result\"]; SampleControl.DataBind(); } <\/script>\n\n<\/head>\n\n<body> <h1>Testing Sample Database<\/h1> <asp:DataGrid runat=\"server\" id=\"SampleControl\" \/> <\/body>\n\n<\/html> [\/COLORIZ]\n\nNext you will need to create a <tt>web.config<\/tt> file. You can copy and paste the the example below. Please note that <tt>Custom Errors<\/tt> have been turned off in this web.config for debugging purposes. The <tt>customErrors mode<\/tt> line should be removed in a production environment.\n\n<strong>File excerpt:<\/strong> <em>\/srv\/www\/ducklington.org\/public_html\/web.config<\/em>\n<pre><configuration>\n        <system.web>\n                <customErrors mode=\"Off\"\/>\n                        <compilation>\n                                <assemblies>\n                        <add assembly=\"MySql.Data\"\/>\n                                <\/assemblies>\n                        <\/compilation>\n        <\/system.web>\n<\/configuration>\n<\/pre>\nVisit the <tt>testdb.aspx<\/tt> file in a web browser.  If you see the text &#8220;Testing Sample Databases&#8221; in your browser with the information that you inserted into the database above, you now have a functioning <tt>mod_mono<\/tt> installation and can continue with the development and deployment of your own application!\n\n<\/div>\n<div id=\"more-information\"><a name=\"more_information\"><\/a>\n<h2>More Information\u00a0<a href=\"http:\/\/library.linode.com\/pCYHOV\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/link-icon.png\" alt=\"Link\"><\/a><\/h2>\nYou 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.\n<ul>\n    <li><a href=\"http:\/\/mono-project.com\/Mod_mono\">Mono Project &#8211; Homepage<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\"><\/li>\n    <li><a href=\"http:\/\/www.mono-project.com\/AutoHosting\">Mono Project &#8211; Autohosting Documentation<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\"><\/li>\n    <li><a href=\"http:\/\/go-mono.com\/config-mod-mono\/\">Mod_Mono Configuration Generator<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\"><\/li>\n    <li><a href=\"https:\/\/help.ubuntu.com\/community\/ModMono\">ModMono &#8211; Ubuntu Community Documentation<\/a>\n<img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\"><\/li>\n<\/ul>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>mod_mono is an Apache module that makes it possible to run ASP.NET applications in Linux environment&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[214,84,171,213,7],"class_list":["post-334","post","type-post","status-publish","format-standard","hentry","category-linux","category-win","tag-apache","tag-asp-net","tag-debian","tag-mono","tag-ubuntu"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=334"}],"version-history":[{"count":0,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/334\/revisions"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=334"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}