Thursday, April 24, 2008

INSTALLING AND SETTING UP APACHE & MONGREAL ON FEDORA

Make sure u r are a root user

1. installing apache
yum install httpd

2. install and setup mongrel
gem install daemons gem_plugin mongrel mongrel_cluster --include-dependencies

3. Configuring the cluster
cd /var/www/app_directory
[u in app directory]$ mongrel_rails cluster::configure -e production \\
-p 8000 \\
-a 127.0.0.1 \\
-N 3 \\

-e : which type of setup.. production or development
i used development. since mine was under dev..

-p : starting port for mongrel_cluster
-a : ip address
-N : number of mongrel instances u wanu run...

this will create a mongrel_cluster.yml file inside /var/www/app_dir/config

4. commands to start and stop mongrel_cluster

[u in app directory]$mongrel_rails cluster::start/restart/stop

Completed this part ur mongrel setup is done dona done done.....

Next step is to configure apache..

5. now move on to ur /etc/httpd/conf directory
Since there is lotta junk in the httpd.conf file
we wil make separate config files for our app...

there ll be four config files in all.. which are as follows...
myapp.common
The common portions of our configuration. Refactoring this out makes it easier
to add additional VirtualHosts down the road (e.g., SSL) while still maintaining
exactly the same configuration.
myapp.conf
The main entry, tying everything together to produce a working Rails app.
myapp.proxy_cluster.conf
A proxy balancer with which to interface with the Mongrel cluster.
myapp.proxy_frontend.conf
An (optional) HTTP front-end for managing the proxy load balancing configuration
on the fly.

===============
myapp.common
===============

ServerName myapp.com
DocumentRoot /var/rails/myapp/current/public


Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all


RewriteEngine On

# Make sure people go to www.myapp.com, not myapp.com
RewriteCond %{HTTP_HOST} ^myapp\.com$ [NC]
RewriteRule ^(.*)$ http://www.myapp.com$1 [R=301,L]
# Yes, I've read no-www.com, but my site already has much Google-Fu on
# www.blah.com. Feel free to comment this out.

# Uncomment for rewrite debugging
#RewriteLog logs/myapp_rewrite_log
#RewriteLogLevel 9

# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]

# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]

# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/xml
application/xml application/xhtml+xml text/javascript text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html

# Uncomment for deflate debugging
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog logs/myapp_deflate_log deflate


============
myapp.conf
============

Include /etc/httpd/conf.d/myapp.common

ErrorLog logs/myapp_errors_log
CustomLog logs/myapp_log combined

======================
myapp.proxy_cluster.conf
======================
This is loaded by Apache to configure a mod_proxy_balancer cluster mapped to
the internal Mongrel servers.

BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002

=======================
myapp.proxy_frontend.conf
=======================

This provides a front-end for the proxy load balancing, which you can access
from inside your server at http://localhost:8080.

Listen 8080
SetHandler balancer-manager
Deny from all
Allow from localhost

6. restart ur httpd
[u in app directory]$/sbin/service httpd restart

Actaully i posted it for my personal reference..
U will find a very good document on the same here
Thanx to Coda Hale... :)

Mongrel cluster restart issues...

hi,
Error : !!! Path to pid file not valid: tmp/pids/mongrel.8000.pid
mongrel::start reported an error. Use mongrel_rails
mongrel::start -h to get help.


Solution : jump into ur application directory
mine is
/var/www/MY_APP
go to config directory..
open your mongrel_cluster.yml file



check out for the log file path
log_file: log/mongrel.log

which is relative... mongrel cant find it... so change it to ...:

log_file: /var/www/MY_APP/log/mongrel.log

similarly, u l have to change the path for pid file

which ll be ... :
pid_file: tmp/pids/mongrel.pid

change it to ... :
pid_file: /var/www/MY_APP/tmp/pids/mongrel.pid

replace MY_APP with ur app name..
and u r done..