16019 How to run Asp.Net Web Forms, MVC2 and MVC3 applications on FreeBSD - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Miscellaneous > Howtos & FAQs (Moderated)

Howtos & FAQs (Moderated) Would you like to share some of your solutions for certain problems? Tips or tricks? Post here. All new topics are automatically moderated.

Reply
 
Thread Tools Display Modes
  #1  
Old August 17th, 2011, 20:57
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default How to run Asp.Net Web Forms, MVC2 and MVC3 applications on FreeBSD

1. Install Mono

Code:
# cd /usr/ports/lang/mono
# make config-recursive
# make install clean
In order to test Mono installation, create a new file /tmp/test.cs:

Code:
using System;
 
class Program {
    static void Main ()
    {
        Type t = Type.GetType ("Mono.Runtime");
        if (t != null)
             Console.WriteLine ("You are running with the Mono VM");
        else
             Console.WriteLine ("You are running something else");
    }
}
Then compile it and run:

Code:
# cd /tmp
# mcs test.cs
# mono test.exe
You are running with the Mono VM
2. Install Nginx web server
Code:
# cd /usr/ports/www/nginx
# make config-recursive
# make install clean
# echo "nginx_enable=YES" >> /etc/rc.conf

Last edited by vand777; August 17th, 2011 at 21:17.
Reply With Quote
  #2  
Old August 17th, 2011, 20:59
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default

3. Install Xsp

Code:
# cd /usr/ports/www/xsp
# make config-recursive
# make install clean
4. Configure Nginx

Edit /usr/local/etc/nginx/nginx.conf file:

Code:
...
user  asp;
worker_processes  4;  # should be equal to number of cores on your server
...
 
        location / {
            fastcgi_pass   192.168.1.100:9000; # change this IP to the IP and port of your fastcgi-mono-server (see below)
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
 
        #location / {
        #    root   /usr/local/www/nginx;
        #    index  index.html index.htm;
        #}
...
Create a new user asp (shell nologin, random password):

Code:
# adduser
...
# mkdir /home/asp/www
# chown asp:asp /home/asp/www/
# chmod 555 /home/asp/www/
# touch /var/log/mono-server4.log
# chown asp:asp /var/log/mono-server4.log
Reply With Quote
  #3  
Old August 17th, 2011, 21:03
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default

5. Configure startup scripts

Create a new file /home/asp/fcgi:

Code:
fastcgi-mono-server4 /socket=tcp:9000 /address=192.168.1.100 /applications=/:. /root=/home/asp/www /logfile=/var/log/mono-server4.log &
Adjust its permissions:

Code:
# chmod ug+x /home/asp/fcgi
Create a startup script for fastcgi-mono-server4 in the /home/asp/fcgi_startup file:

Code:
#!/usr/local/bin/bash
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:$HOME/bin:; export PATH
PID=`/bin/ps waux | /usr/bin/grep mono | /usr/bin/grep -v grep | /usr/bin/awk '{ print $2 }'`
 
if  ps waux | grep mono | grep -v grep > /dev/null
 then
        echo "fastcgi-mono-server4 seems to run on PID $PID"
        exit
else
    echo "fastcgi-mono-server4 is not running. Starting it"
    /home/asp/fcgi
fi
Make it executable:

Code:
# chmod ug+x /home/asp/fcgi_startup
Now add the job to crontab:

Code:
# crontab -uasp -e
And then add the following line to crontab file:

Code:
* * * * * /home/asp/fcgi_startup > /home/asp/mono_laststate
Start Nginx:

Code:
# /usr/local/etc/rc.d/nginx start
Do not forget to adjust firewall rules.

Last edited by vand777; August 17th, 2011 at 21:25.
Reply With Quote
  #4  
Old August 17th, 2011, 21:05
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default

Test it

Create a new file /home/asp/www/hello.aspx:

Code:
<html>
<body>
<p>It works! <% =Environment.OSVersion.ToString() %></p>
</body>
</html>
And then request it at http://your.ip.address/hello.aspx. It should give you the version of your operating system. It displays on my system:

Code:
It works! Unix 8.2.2.0
Reply With Quote
  #5  
Old August 17th, 2011, 21:11
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default

Asp.Net Web Forms and MVC2 applications

Asp.Net Web Forms and MVC2 applications should work automatically under this setup (Mono 2.10.2). Just copy files into the /home/asp/www/ folder.

Asp.Net MVC3 applications


In order to make Asp.Net MVC3 applications working under Mono 2.10.2, you have to copy additional files from your Windows development workstation into your project's bin directory (these files will finally end up in /home/asp/www/bin folder):
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.xml
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\NuGet.Core.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Helpers.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Helpers.xml
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.xml
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.xml
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Administ ration.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Deployme nt.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Deployme nt.xml
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Razor.dl l
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Razor.xm l
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\WebMatrix.Data.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\WebMatrix.Data.xml
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\WebMatrix.WebData.dll
  • c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\WebMatrix.WebData.xml

Also you have to delete EntityFramework.xml and EntityFramework.dll from /home/asp/www/bin folder after you have copied your project there.

Please read the section "ASP.NET MVC3 Support" on Mono 2.10 Release Notes for the details.

Last edited by vand777; August 17th, 2011 at 21:19.
Reply With Quote
  #6  
Old August 17th, 2011, 21:15
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default

Should you have any problems when building or running mono, please do not forget to read /usr/ports/lang/mono/pkg-message message. Maybe you will find the solution to your problem.

For example, this part might be important:
Code:
* If you are in a jailed environment, ensure System V IPC are enabled.
  You can rely on the security.jail.sysvipc_allowed  sysctl to check
  this status.  The following enables this feature on the host system:
    # echo "jail_sysvipc_allow=\"YES\"" >> /etc/rc.conf
The above tutorial was tested in jail on FreeBSD 8.2p2, Mono 2.10.2.
Reply With Quote
  #7  
Old August 17th, 2011, 21:16
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default

Reserved
Reply With Quote
  #8  
Old August 17th, 2011, 21:16
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default

Reserved2
Reply With Quote
  #9  
Old November 29th, 2011, 07:08
Claud Claud is offline
Junior Member
 
Join Date: Nov 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hello,
Excelent tutorial thanks,
First, i don`t have bash as a default shell script fomr my user and it seems that the startup script needs some adjustemts or it will return bash pid olso , so the script that worked for me was:
Code:
#!/usr/local/bin/bash
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:$HOME/bin:; export PATH
PID=`/bin/ps waux | /usr/bin/grep mono | /usr/bin/grep -v grep | /usr/bin/grep -v /bin/bash | /usr/bin/awk '{ print $2 }'`
 
if  ps waux | grep mono | grep -v grep | grep -v /bin/bash > /dev/null
 then
        echo "fastcgi-mono-server4 seems to run on PID $PID"
        exit
else
    echo "fastcgi-mono-server4 is not running. Starting it"
    /home/asp/fcgi
fi
Hope someone finds it useful.

Last edited by DutchDaemon; November 30th, 2011 at 01:12. Reason: re-read: proper formatting: http://forums.freebsd.org/showthread.php?t=8816
Reply With Quote
  #10  
Old December 3rd, 2011, 20:16
vand777 vand777 is offline
Member
 
Join Date: Jun 2010
Location: London
Posts: 282
Thanks: 29
Thanked 33 Times in 27 Posts
Default

Thank you, Claud!
Reply With Quote
  #11  
Old December 3rd, 2011, 22:20
wblock@'s Avatar
wblock@ wblock@ is online now
Moderator
 
Join Date: Sep 2009
Location: Milky Way galaxy
Posts: 7,723
Thanks: 432
Thanked 1,761 Times in 1,458 Posts
Default

Quote:
Originally Posted by Claud View Post
Code:
...
PID=`/bin/ps waux | /usr/bin/grep mono | /usr/bin/grep -v grep | /usr/bin/grep -v /bin/bash | /usr/bin/awk '{ print $2 }'`
...
should be replaceable with

Code:
PID=`/usr/bin/pgrep mono`
Reply With Quote
Reply

Tags
asp.net, fastcgi-mono-server4, mono, mvc2, mvc3

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Solved] Problem building net-mgmt/net-snmp jkcarrol Installation and Maintenance of FreeBSD Ports or Packages 4 August 5th, 2010 23:53
bsnmp vs. net-mgmt/net-smtp ondra_knezour Web & Network Services 1 April 26th, 2010 04:26
PDF forms Oko Installation and Maintenance of FreeBSD Ports or Packages 5 April 20th, 2010 22:18
howto install freeBSD on iMac/howto boot from CD leizhenhua Other Architectures 1 June 15th, 2009 06:09
How to set and run net-flow DEViATIO Installation and Maintenance of FreeBSD Ports or Packages 5 March 31st, 2009 13:32


All times are GMT +1. The time now is 19:00.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0