<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wazi &#187; Freddy Andersen</title>
	<atom:link href="http://olex.openlogic.com/wazi/author/fandersen/feed/" rel="self" type="application/rss+xml" />
	<link>http://olex.openlogic.com/wazi</link>
	<description>Open Source Articles, Tutorials and Licensing Information</description>
	<lastBuildDate>Mon, 30 Aug 2010 20:40:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing Apache HTTP Server with a Quick-Start Config</title>
		<link>http://olex.openlogic.com/wazi/2009/installing-apache-http-server-with-quick-start-config/</link>
		<comments>http://olex.openlogic.com/wazi/2009/installing-apache-http-server-with-quick-start-config/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 16:04:56 +0000</pubDate>
		<dc:creator>Freddy Andersen</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[GroundWork]]></category>
		<category><![CDATA[Hyperic]]></category>
		<category><![CDATA[mod_jk]]></category>
		<category><![CDATA[mod_proxy]]></category>
		<category><![CDATA[Mongrel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://olex.openlogic.com/wazi/?p=40435</guid>
		<description><![CDATA[The Apache HTTP Server is one of the most widely used open source software packages, so it's no surprise that we get lots of questions about Apache installation procedures.  Fortunately, we have tons of experience with Apache installations, and we've distilled our years of experience into this handy tutorial.]]></description>
			<content:encoded><![CDATA[<div style='padding:10px;border:1px solid;margin-bottom:20px;'>This article, <a href='http://olex.openlogic.com/wazi/2009/installing-apache-http-server-with-quick-start-config/'>Installing Apache HTTP Server with a Quick-Start Config</a>, originally appeared on <a
      href='http://olex.openlogic.com/wazi'>Wazi</a>, a free source for news, information, and articles on open source software.</div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2009%2Finstalling-apache-http-server-with-quick-start-config%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2009%2Finstalling-apache-http-server-with-quick-start-config%2F&amp;source=OpenLogic&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>The <a href="https://olex.openlogic.com/packages/apache">Apache HTTP Server</a> has been the <a href="http://httpd.apache.org/" target="_blank">most popular web server on the Internet since April 1996</a> and is one of the most widely used open source software packages.  In fact, the <a href="http://news.netcraft.com/archives/2009/06/17/june_2009_web_server_survey.html" target="_blank">latest Netcraft Web Server Survey</a> reports that more than half of all active web sites use Apache, making it more widely used than all other Web servers combined.  So it&#8217;s no surprise that we get lots of questions about Apache HTTP Server installation procedures.  Fortunately, we have tons of experience with Apache installations, and we&#8217;ve distilled our years of experience into this handy tutorial.</p>
<h2>Before You Start</h2>
<p>This article assumes that you have Red Hat/CentOS Linux with a proper build environment setup.  If you do not have <a href="https://olex.openlogic.com/packages/gcc" target="_blank">GCC</a> installed you can get this with all the required packages like this:</p>
<pre>yum groupinstall "Development Libraries"</pre>
<p>You should now be ready to install Apache!</p>
<h2>Meat &amp; Potatoes</h2>
<p>When we install Apache HTTP Server either for ourselves a client — small or large — we follow a &#8220;standard&#8221; configuration setup that&#8217;s very easy to build on later.  For the most part we use CentOS or Red Hat Enterprise edition servers, but these steps should work on any Unix system.  This might not be true for AIX, which requires a little more hand-holding to make sure the compiler is installed correctly.</p>
<p>The steps we&#8217;ll cover in this article are:</p>
<ul>
<li>Download the source code for the latest version of Apache (currently 2.2.11) from OpenLogic Exchange (OLEX) or the Apache project website.</li>
<li>Execute the configure, make, and make install installation steps (with a few custom switches).</li>
<li>Setup the httpd.conf and associated files.</li>
<li>Start your newly built Apache server.</li>
<li>Done!</li>
</ul>
<h3>Download Apache</h3>
<p>The first step is to download the Apache source code, not binaries or RPMs.  We believe that using the source code gives the best performing, most flexible installation of Apache.  If you follow a few simple steps the actual &#8220;installation&#8221; procedure is not difficult, and you&#8217;ll have a good foundation to add or remove features later.</p>
<p>To download the source source code, go to <a href="https://olex.openlogic.com/packages/apache">OpenLogic Exchange (OLEX)</a> or the <a href="http://httpd.apache.org/download.cgi" target="_blank">Apache downloads site</a> and look for the latest ZIP, TGZ, or BZ2 file (currently version 2.2.11).</p>
<h3>Compiling/Installing the Source for Apache</h3>
<p>We like to keep our source downloads in ~/Software/ so it&#8217;s easy go back and re-compile and re-install the binaries if we need to add a module or two.  With the source saved under ~/Software/httpd-2.2.11, compile Apache HTTP Server with the following configure string:</p>
<pre>[root@coco ~]# cd ~/Software/httpd-2.2.11
[root@coco httpd-2.2.11]# "./configure"
"--enable-ssl"
"--enable-proxy"
"--enable-proxy-balancer"
"--enable-rewrite"
"--enable-headers"
"--enable-deflate"
"--enable-cache"
"--enable-expires"
"--enable-mem-cache"
"--enable-disk-cache"
"--enable-file-cache"
"--with-mpm=worker"
"--disable-cgi --disable-asis"
"--disable-autoindex"
"--disable-userdir"</pre>
<p>Here&#8217;s a brief explanation of the configuration options shown above:</p>
<ul>
<li><strong>enable-ssl</strong>: This will allow you to enable a secure port later.</li>
<li><strong>enable-proxy/enable-proxy-balancer</strong>: This will setup a connection to a back-end server like <a href="https://olex.openlogic.com/packages/tomcat">Tomcat</a> or <a href="https://olex.openlogic.com/packages/mongrel">Mongrel</a></li>
<li><strong>enable-rewrite</strong>: We&#8217;re always going to need rewrite rules in the config file.</li>
<li><strong>enable-headers</strong>: We need this to enable monitoring of the server, and for mod_proxy we need to manipulate the header.</li>
<li><strong>enable-deflate</strong>: Enables the old gzip module, which will allow us to setup some content to be compressed with gzip.</li>
<li><strong>enable-cache/expires/mem-cache/disk-cache/file-cache</strong>: These are all included so we can enable the expires module.</li>
<li><strong>with-mpm=worker</strong>: We&#8217;re choosing to use the worker MPM as the default since most servers we work with have more than one CPU.  Use the prefork MPM if you&#8217;re working on a server that has only one CPU.</li>
</ul>
<p>Next, run the following to install Apache HTTP Server:</p>
<pre>[root@coco httpd-2.2.11]# make &amp;&amp; make install</pre>
<p>The Apache server should now be installed in <strong>/usr/local/apache2</strong>, which is the default installation directory.  To change the Apache installation directory you&#8217;ll need to add the &#8211;prefix=/my/directory/apache2 switch to the configure string, and then run the make &amp;&amp; make install command as shown above.</p>
<h3>Apache Startup Script</h3>
<p>The easiest and fastest way to start Apache is to copy /usr/local/apache2/bin/apachectl to /etc/init.d/apache. This will allow you to do /etc/init.d/apache start|stop|restart.</p>
<p>If you want a script that has more feedback you can use the following:</p>
<pre>#!/bin/bash
# httpd        Startup script for the Apache HTTP Server
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.  It is used to serve
#              HTML files and CGI.
# processname: httpd
# config: /usr/local/apache2/conf/httpd.conf
# pidfile: /var/run/apache2.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/apache2.pid}
lockfile=${LOCKFILE-/var/lock/subsys/apache2}
RETVAL=0

start() {
 echo -n $"Starting $prog: "
 LANG=$HTTPD_LANG daemon $httpd $OPTIONS
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] &amp;&amp; touch ${lockfile}
 return $RETVAL
}
stop() {
 echo -n $"Stopping $prog: "
 killproc $httpd
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] &amp;&amp; rm -f ${lockfile} ${pidfile}
}
reload() {
 echo -n $"Reloading $prog: "
 if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t &gt;&amp;/dev/null; then
 RETVAL=$?
 echo $"not reloading due to configuration syntax error"
 failure $"not reloading $httpd due to configuration syntax error"
 else
 killproc $httpd -HUP
 RETVAL=$?
 fi
 echo
}

# See how we were called.
case "$1" in
 start)
 start
 ;;
 stop)
 stop
 ;;
 status)
 status $httpd
 RETVAL=$?
 ;;
 restart)
 stop
 start
 ;;
 condrestart)
 if [ -f ${pidfile} ] ; then
 stop
 start
 fi
 ;;
 reload)
 reload
 ;;
 graceful|help|configtest|fullstatus)
 $apachectl $@
 RETVAL=$?
 ;;
 *)
 echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
 exit 1
esac

exit $RETVAL</pre>
<a class="wazi-ad-link" href="http://www.openlogic.com/open-source-support.php "><img width="590" height="75" src="http://olex.openlogic.com/wazi/wp-content/uploads/2010/05/open-source-support-main.png" class="attachment-maincontent_ad" alt="Get open source software support" title="Get open source software support" /></a>
<h3>Apache Configuration File</h3>
<p>The main configuration file we use as a template for Apache servers has a few different sections that are important to understand.</p>
<pre># =================================================
# Basic Settings
# =================================================
ServerName %{SERVER_NAME}
ServerRoot "/usr/local/apache2"
PidFile "/var/run/apache2.pid"
# =================================================
# Performance Settings
# =================================================
Timeout 30
KeepAlive On
MaxKeepAliveRequests 500
KeepAliveTimeout 2
&lt;IfModule mpm_prefork_module&gt;
 StartServers            1
 MinSpareServers         1
 MaxSpareServers         10
 MaxClients              25
 MaxRequestsPerChild     1000
&lt;/IfModule&gt;
&lt;IfModule mpm_worker_module&gt;
 ServerLimit             16
 StartServers             2
 MaxClients              40
 MinSpareThreads          5
 MaxSpareThreads         20
 ThreadsPerChild         20
 MaxRequestsPerChild   5000
&lt;/IfModule&gt;</pre>
<p>The Basic Settings section just defines the root directory of Apache, but the Performance Settings section has a few noteworthy options.  We have a Timeout of 30 seconds, which is enough for most setups (the default of 300 is way too long).  We enable KeepAlive, but the KeepAlive timeout is only 2 seconds.  This allows each user to get their own connection, but the connection will close as soon as they download the page they requested (you can play with this timeout, but you&#8217;ll most likely want to have it set somewhere in the 1-5 sec range). Next, we setup prefork and worker based on the number of CPUs that are installed on the Apache server.</p>
<pre># =================================================
# General Settings
# =================================================
Listen 80
# Listen 443
User www
Group www
ServerAdmin webmaster@openlogic.com
UseCanonicalName Off
ServerTokens Prod
ServerSignature Off
HostnameLookups Off
ExtendedStatus On
# =================================================
# Modules
# =================================================
#LoadModule dummy_module /usr/lib/apache2/modules/mod_dummy.so</pre>
<p>In the General Settings section we set Listen to port 80, but we also have port 443 as an option to choose from (we’ll show you how to setup a https/SSL/secure virtual host later).  User and Group are set to the www user, which is a system user (note that on Red Hat you create a system user with the -r switch <em>adduser -r www</em>).  We don&#8217;t want the server to look up hostname or show a signature to our users, so those options are disabled.  The ExtendedStatus option is enabled for monitoring reasons.  And in the Modules section, the dummy module is there in case we want to install <a href="https://olex.openlogic.com/packages/php">PHP</a> later on.</p>
<pre># =================================================
# Access Control
# =================================================
&lt;Directory /&gt;
 Options FollowSymLinks
 AllowOverride None
 Order deny,allow
 Deny from all
&lt;/Directory&gt;
&lt;DirectoryMatch "^/.*/.svn/"&gt;
 ErrorDocument 403 /404.html
 Order allow,deny
 Deny from all
 Satisfy All
&lt;/DirectoryMatch&gt;
&lt;FilesMatch "^.ht"&gt;
 Order allow,deny
 Deny from all
 Satisfy All
&lt;/FilesMatch&gt;
# =================================================
# MIME Encoding
# =================================================
DefaultType text/plain
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl</pre>
<p>Needless to say, the Access Control section contains some important options.  Deny from all makes sure we have to allow access to any directory that&#8217;s used in the Apache configuration.  Then, we make sure that users don&#8217;t have access to .svn directories or .ht files.  In the MIME Encoding section we have a minimal mime.type setup for the deflate and SSL modules.</p>
<pre># =================================================
# Logs
# =================================================
LogLevel warn
LogFormat "%h %l %u %t "%r" %&gt;s %b "%{Referer}i" "%{User-Agent}i"" combined
ErrorLog /usr/local/apache2/logs/error_log
# Mark requests for the robots.txt file
SetEnvIf Request_URI "^/robots.txt$" dontlog
SetEnvIf Request_URI "^/monit/token$" dontlog
# =================================================
# SSL Configuration
# =================================================
SSLPassPhraseDialog  builtin
SSLSessionCache        shmcb:/usr/local/apache2/logs/ssl_scache(512000)
SSLSessionCacheTimeout  300
SSLMutex  file:/usr/local/apache2/logs/ssl_mutex
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin</pre>
<p>Next, we setup the LogFormat for use in our virtual hosts and the server error log file.  We also have two dontlog Env settings to remove the robot.txt and monit/token hits from the log.  (We&#8217;ll show how this is used when we create the virtual host.)  We also setup a default SSL configuration for the server.</p>
<pre># =================================================
# Mod Status for Monitoring
# =================================================
&lt;VirtualHost 127.0.0.1:80&gt;
 &lt;Location /server-status&gt;
 SetHandler server-status
 Order Deny,Allow
 Deny from all
 Allow from localhost
 Allow from 127.0.0.1
 &lt;/Location&gt;
&lt;/VirtualHost&gt;
# =================================================
# Include Extra Configs
# =================================================
Include conf/extra/httpd-myblog.com.conf</pre>
<p>In the Mod Status for Monitoring section we get to the server monitoring setup.  We start by allowing only access from localhost, and we specify that it will only listen to the 127.0.0.1 IP.  This is a good setup for tools like <a href="https://olex.openlogic.com/packages/groundwork">GroundWork</a> and <a href="https://olex.openlogic.com/packages/hyperic-hq">Hyperic</a>.  The last line includes a virtual host configuration file.  Now let&#8217;s have a look at the virtual host.</p>
<h4>Virtual Hosts Using a Name-Based Setup</h4>
<p>We like to configure our httpd.conf with server-wide settings while keeping it free of actual content hosting elements or mod_proxy/mod_jk configurations.  In this example we have a blog that&#8217;s running on a <a href="https://olex.openlogic.com/packages/ruby">Ruby</a> on <a href="https://olex.openlogic.com/packages/ruby">Rails</a> back-end with three Thin servers listening to ports 8000-8002 (Thin an application server that can be used for RoR as an alternative to Tomcat or Mongrel).</p>
<pre># --------------------------------------------------------
# Always Keep the Host Header
# --------------------------------------------------------
ProxyPreserveHost On
# --------------------------------------------------------
# Rails Cluster
# --------------------------------------------------------
&lt;Proxy balancer://rails-cluster&gt;
  BalancerMember http://127.0.0.1:8000
  BalancerMember http://127.0.0.1:8001
  BalancerMember http://127.0.0.1:8002
&lt;/Proxy&gt;</pre>
<p>This setup has three servers in a proxy_balancer cluster that you can access using balancer://rails-cluster/ just as though it was one server.</p>
<pre># --------------------------------------------------------
# Name-Based Virtual Hosting
# --------------------------------------------------------
NameVirtualHost *:80

&lt;VirtualHost *:80&gt;
 DocumentRoot "/var/www/myblog.com/current/public"
 ServerName www.myblog.com
 ServerAlias myblog.com

 # -------------------------------------------------
 # Rewrite Rules
 # -------------------------------------------------
 RewriteEngine on

 # Force www.myblog.com and make sure we use a 301 HTTP code for the
 # redirect. This is a SEO must.
 RewriteCond %{HTTP_HOST}   !^www.myblog.com [NC]
 RewriteCond %{HTTP_HOST}   !^$
 RewriteRule ^/(.*)         http://www.myblog.com/$1 [L,R=301]

 # --------------------------------------------------------
 # List of URLs Not to Proxy
 # --------------------------------------------------------
 ProxyPass /system !
 ProxyPass /images !
 ProxyPass /stylesheets !
 ProxyPass /javascripts !
 ProxyPass /monit/token !
 # Send everything else to the proxy_balancer cluster of rails servers
 ProxyPass / balancer://rails-cluster/
 ProxyPassReverse / balancer://rails-cluster/

 &lt;Directory "/var/www/myblog.com/current/public"&gt;
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
 &lt;/Directory&gt;
 # Before you restart the server you need to create the logs/myblog.com
 # directory.
 # We are also adding the dontlog environment variable here to stop
 # logging the set entries. (This is configured in your httpd.conf)
 ErrorLog  "logs/myblog.com/error_log"
 CustomLog "logs/myblog.com/access_log" combined env=!dontlog

 # --------------------------------------------------------
 # Deflate Module Configuration
 # --------------------------------------------------------
 &lt;IfModule deflate_module&gt;
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/atom_xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/x-httpd-php
  AddOutputFilterByType DEFLATE application/x-httpd-fastphp
  AddOutputFilterByType DEFLATE application/x-httpd-eruby
  AddOutputFilterByType DEFLATE text/html
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
 &lt;/IfModule&gt;
 # =============================================
 # Configure Expires Module
 # =============================================
 &lt;IfModule mod_expires.c&gt;
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 1 week"
  ExpiresByType image/jpeg "access plus 1 week"
  ExpiresByType image/png "access plus 1 week"
  ExpiresByType text/css "access plus 1 week"
  ExpiresByType text/javascript "access plus 1 week"
  ExpiresByType application/x-javascript "access plus 1 week"
  ExpiresByType text/xml "access plus 1 seconds"
 &lt;/IfModule&gt;
&lt;/VirtualHost&gt;</pre>
<p>There&#8217;s a lot of information here, so lets take it step by step.  First, we setup a server with the name www.myblog.com that also listens to myblog.com, but by using mod_rewrite we force everyone to www.myblog.com with a 301 redirect.  Next, we setup all of the static content that we want Apache to serve from the local file system using ProxyPass with a ! to say &#8220;do not proxypass&#8221; these directories, and then we send everything else to the balancer cluster.  We setup the access rights to the static directory where our content (like images, JavaScript, uploaded files, and CSS) is stored.  Then, we setup the virtualhosts log file in its own directory inside the logs directory.  The mod_deflate and mod_expires configurations work for most setups, but this piece needs to be monitored and tuned to your setup.  We&#8217;ve seen the mod_expires setup cause problems using Rails and authentication.</p>
<p>Now, off to a secure.myblog.com virtual host:</p>
<pre>&lt;VirtualHost _default_:443&gt;
 DocumentRoot "/var/www/myblog.com/current/public"
 ServerName secure.myblog.com
 ServerAlias www.myblog.com myblog.com
 RewriteCond %{HTTP_HOST}   !^secure.myblog.com [NC]
 RewriteCond %{HTTP_HOST}   !^$
 RewriteRule ^/(.*)         https://secure.myblog.com/$1 [L,R=301]
 # --------------------------------------------------------
 # List of URLs Not to Proxy
 # --------------------------------------------------------
 ProxyPass /system !
 ProxyPass /images !
 ProxyPass /stylesheets !
 ProxyPass /javascripts !
 ProxyPass / balancer://rails-cluster/
 ProxyPassReverse / balancer://rails-cluster/

 ErrorLog  "logs/myblog.com/error_log"
 CustomLog "logs/myblog.com/access_log" combined env=!donlog

 # --------------------------------------------------------
 # SSL Certificates
 # --------------------------------------------------------
 SSLEngine on
 SSLCertificateFile    /usr/local/apache2/ssl/secure.myblog.com.crt
 SSLCertificateKeyFile /usr/local/apache2/ssl/secure.myblog.com.key
 # --------------------------------------------------------
 # Deflate Module Configuration
 # --------------------------------------------------------
 &lt;IfModule deflate_module&gt;
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/atom_xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/x-httpd-php
  AddOutputFilterByType DEFLATE application/x-httpd-fastphp
  AddOutputFilterByType DEFLATE application/x-httpd-eruby
  AddOutputFilterByType DEFLATE text/html
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
 &lt;/IfModule&gt;
 # =============================================
 # Configure Expires Module
 # =============================================
 &lt;IfModule mod_expires.c&gt;
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 1 week"
  ExpiresByType image/jpeg "access plus 1 week"
  ExpiresByType image/png "access plus 1 week"
  ExpiresByType text/css "access plus 1 week"
  ExpiresByType text/javascript "access plus 1 week"
  ExpiresByType application/x-javascript "access plus 1 week"
  ExpiresByType text/xml "access plus 1 seconds"
 &lt;/IfModule&gt;
 # --------------------------------------------------------
 # Document Root /
 # --------------------------------------------------------
 &lt;Directory "/var/www/myblog.com/current/public"&gt;
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
 &lt;/Directory&gt;
 # -------------------------------------------------
 # Fixing Yet Another IE 6 Bug
 # -------------------------------------------------
 BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
 # -------------------------------------------------
 # Add this to the request header so that
 # Rails puts the correct redirect in place
 # -------------------------------------------------
 RequestHeader set X_FORWARDED_PROTO 'https'
&lt;/VirtualHost&gt;</pre>
<p>This is very similar to the port 80 virtual host of the same name.  The biggest difference is with the SSL certificates and the bottom SSL/https settings to fix issues with Mongrel/Rails and IE6.  You can&#8217;t configure mod_expires and mod_deflate in the main configuration file and have the virtual host inheret the configuration, so the best solution to be dry is to put these settings in their own mod_deflate.conf and mod_expires.conf and then include the named configuration files in each virtualhosts configuration file like so:</p>
<pre>Include conf/mod_deflate.conf
Include conf/mod_expires.conf</pre>
<h2>Finishing Up</h2>
<p>Apache with mod_proxy rocks.  After working through the above steps we have an Apache installation that is ready to be expanded to a high performance web server or proxy server, or both.  We like to start with this setup and then build from here.  If you need to get more concurrent clients and throughput on your Apache server, take a look at your available memory and CPU cycles and consider doing something like this:</p>
<pre>&lt;IfModule mpm_worker_module&gt;
  ThreadLimit 100
  StartServers 5
  MaxClients 1000
  MinSpareThreads 100
  MaxSpareThreads 1000
  ThreadsPerChild 100
  MaxRequestsPerChild 0
&lt;/IfModule&gt;</pre>
<p>This is a high threads and low processes setup, and to get the number of processes that Apache will use simply divide MaxClients by ThreadPerChild.  So, this gives us 10 processes each with a maximum of 100 threads, with a maximum of 1000 clients total.  Depending on the server and type of content that you are serving you can load test and increase these settings if you need more than 1000 concurrent users.</p>
<p>We&#8217;re very big fans of mod_proxy, and we use mod_proxy_ajp in place of <a href="https://olex.openlogic.com/packages/mod_jk">mod_jk</a> every chance we get.  We also talk a lot of customers into using mod_proxy over mod_jk if they&#8217;re using Apache 2.2.x.</p>
<p>Using this setup to include the virtual hosts that the server runs, it&#8217;s easy to add and remove new websites.  It also provides a good overview of what&#8217;s running on the server.</p>
]]></content:encoded>
			<wfw:commentRss>http://olex.openlogic.com/wazi/2009/installing-apache-http-server-with-quick-start-config/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL 5.1 is GA</title>
		<link>http://olex.openlogic.com/wazi/2008/mysql-51-is-ga/</link>
		<comments>http://olex.openlogic.com/wazi/2008/mysql-51-is-ga/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 22:12:44 +0000</pubDate>
		<dc:creator>Freddy Andersen</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://olex.openlogic.com/wazi/?p=1642</guid>
		<description><![CDATA[MySQL 5.1 GA has been released with a number of new features and performance enhancements...]]></description>
			<content:encoded><![CDATA[<div style='padding:10px;border:1px solid;margin-bottom:20px;'>This article, <a href='http://olex.openlogic.com/wazi/2008/mysql-51-is-ga/'>MySQL 5.1 is GA</a>, originally appeared on <a
      href='http://olex.openlogic.com/wazi'>Wazi</a>, a free source for news, information, and articles on open source software.</div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2008%2Fmysql-51-is-ga%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2008%2Fmysql-51-is-ga%2F&amp;source=OpenLogic&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Sun has just made <a href="https://olex.openlogic.com/packages/mysql#2133">MySQL 5.1</a> GA with a number of new features and performance enhancements. The first available release was 5.1.3 in November of 2005! Then MySQL 5.1 had the first Release Candidate 5.1.22 in September of 2007</p>
<h3>What&#8217;s Different</h3>
<p>There is a loooooong list of changes for this release. Sun/MySQL have been working on this version for years so that&#8217;s to be expected. Despite that, upgrading from a prior 5.0.x release is painless and they have even added a upgrade helper.</p>
<p>Here are some of the new features:</p>
<ul>
<li><strong>Partitioning:</strong> Increased Performance, the optimizer knows about the partitions and what data is stored in the partition so mysql will access only those necessary partitions during query execution. Simplified Data Management, if designing the data structure correctly you can get an easier/cleaner database that will be easier to manage.</li>
<li><strong>Event Scheduler:</strong> This tool has been missing in MySQL. Moving common recurring SQL-based tasks to execute on the database server and not in cron/windows scheduler is a very welcome feature.</li>
<li><strong>Row-Based and Hybrid Replication: </strong>There are so many wins that you get from using row-based replication and I feel this is a great feature that was added to 5.1. The new default to 5.1.30 is the hybrid mode which downgrades to statement based replication. The MySQL manual has a good pros and cons for the two http://dev.mysql.com/doc/refman/5.1/en/replication-sbr-rbr.html.</li>
<li><strong>MySQL Cluster: </strong>This is now a separate product which has to be added if you want to use the NDB cluster engine. Pay attention here as this move confused people since the Cluster version is now at 6.3.</li>
<li><strong>Tablespace Backup: </strong>You can now use mysqldump &#8211;all-tablespaces to dump a NDCLUSTER tablespace.</li>
<li><strong>mysql_upgrade:</strong> Checks all tables in all databases for         incompatibilities with the current version of MySQL Server. If a         table is found to have a possible incompatibility, it is         checked. If any problems are found, the table is repaired. With multiple mysql servers running on one db server use <em>mysql_upgrade -p 3307</em>.</li>
</ul>
<h3>Talk of the Town</h3>
<p>There has been much talk about the new release and &#8220;if&#8221; this release is production ready. It is our belief that this release is production ready. For our applications, we have been running 5.1 for 6 months in production without hitting one single bug. That said, we caution you to make this decision on your own, with proper testing. We recommend that you read the MySQL bugs list, and install a test server where you can run tests with your environment.</p>
<h3>Dig Deeper</h3>
<p>Here&#8217;s the extensive list of changes for <a href="http://dev.mysql.com/doc/refman/5.1/en/news-5-1-x.html" target="_blank">MySQL 5.1.x</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://olex.openlogic.com/wazi/2008/mysql-51-is-ga/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JRuby and Glassfish on Rails Part II: Setting up a Production Environment on Red Hat Linux</title>
		<link>http://olex.openlogic.com/wazi/2008/jruby-and-glassfish-a-production-ruby-on-rails-environment/</link>
		<comments>http://olex.openlogic.com/wazi/2008/jruby-and-glassfish-a-production-ruby-on-rails-environment/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 19:40:17 +0000</pubDate>
		<dc:creator>Freddy Andersen</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://olex.openlogic.com/wazi/?p=1409</guid>
		<description><![CDATA[Learn to deploy a Ruby on Rails application into a production-ready JRuby on Rails environment running GlassFish.]]></description>
			<content:encoded><![CDATA[<div style='padding:10px;border:1px solid;margin-bottom:20px;'>This article, <a href='http://olex.openlogic.com/wazi/2008/jruby-and-glassfish-a-production-ruby-on-rails-environment/'>JRuby and Glassfish on Rails Part II: Setting up a Production Environment on Red Hat Linux</a>, originally appeared on <a
      href='http://olex.openlogic.com/wazi'>Wazi</a>, a free source for news, information, and articles on open source software.</div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2008%2Fjruby-and-glassfish-a-production-ruby-on-rails-environment%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2008%2Fjruby-and-glassfish-a-production-ruby-on-rails-environment%2F&amp;source=OpenLogic&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Now we&#8217;ll deploy a <a title="Ruby in OLEX" href="https://olex.openlogic.com/packages/ruby" target="_blank">Ruby</a> on <a title="Rails in OLEX" href="https://olex.openlogic.com/packages/glassfish" target="_blank">Rails</a> application (we&#8217;ll use a ready-to-deploy Rails application, Radiant, that drops into this environment easily) into a production-ready <a title="JRuby in OLEX" href="https://olex.openlogic.com/packages/glassfish" target="_blank">JRuby</a> on Rails environment running GlassFish. This tutorial does not cover tuning any parameters, but focuses rather on getting the server installed and running, and successfully deploying a Rails application into the <a title="GlassFish in OLEX" href="https://olex.openlogic.com/packages/glassfish" target="_blank">GlassFish</a> container.</p>
<h2>Before You Start</h2>
<p>We will use a RedHat ES 5 server for this tutorial. We&#8217;ve chosen the latest stable binary of JRuby 1.1.5 and we will use <a title="GlassFish in OLEX" href="https://olex.openlogic.com/packages/glassfish" target="_blank">GlassFish</a> v2. I think that&#8217;s all we need to know before we jump into the &#8230;</p>
<h2>Meat &amp; Potatoes</h2>
<h3><span style="#993300;"><strong><span style="#800000;"><span style="underline;">Installing JRuby</span></span></strong></span></h3>
<ol>
<li>Download the latest <a title="JRuby in OLEX" href="https://olex.openlogic.com/packages/jruby" target="_self">JRuby release from OLEX</a>.</li>
<li>Unzip and copy the JRuby directory to your /usr/local/ directory. (If you don&#8217;t like the /usr/local/ area but are more of a /opt sort, that&#8217;s fine, too, but this tutorial will reference /usr/local/ as the install location.)</li>
<li>Create a file /etc/profile.d/jruby.sh and add the following content:</li>
<li>Log-out and log-in to your system, this will make sure the environment for JRuby is correctly setup.</li>
<li>Test JRuby with the following command:<br />
<code><em>export JRUBY_HOME=/usr/local/jruby<br />
export PATH=$PATH:$JRUBY_HOME/bin</em></code><br />
<code>[freddy@wazi]# jruby -v<br />
jruby 1.1.5 (ruby 1.8.6 patchlevel 114) (2008-11-03 rev 7996) [amd64-java]</code></li>
</ol>
<p>That&#8217;s working great!</p>
<h3>Install Rails</h3>
<p>The recommended way to run these commands (known as <code>system-level executable commands</code>) in JRuby is to always use <code>jruby -S</code>.</p>
<p style="30px;"><code>[freddy@wazi]# jruby -S gem install <strong>rubygems-update</strong><br />
[freddy@wazi]# jruby -S <strong>update_rubygems</strong><br />
[freddy@wazi]# jruby -S gem install <strong>jruby-openssl</strong><br />
[freddy@wazi]# jruby -S gem install <strong>rails activerecord-jdbcmysql-adapter warbler<br />
</strong></code></p>
<p style="30px;">[freddy@wazi]# jruby -S rails -v Rails 2.2.2</p>
<p>We are going to use Radiant CMS for some simple testing, so let&#8217;s install and setup Radiant&#8230;</p>
<p style="30px;"><code>[freddy@wazi]# jruby -S gem install radiant<br />
[freddy@wazi]# jruby -S radiant --database mysql /usr/local/wazi-radiant<br />
[freddy@wazi]# mysqladmin create wazi-radiant_production</code></p>
<p>We are not going to set up any security for the <a title="MySQL in OLEX" href="https://olex.openlogic.com/packages/mysql" target="_blank">MySQL</a> instance; that&#8217;s a different topic altogether. For this reason, a local MySQL server in conjunction with the root user should work.</p>
<pre style="30px;"><code>=&gt; /usr/local/wazi-radiant/config/database.yml &lt;=</code></pre>
<pre style="30px;">production:
adapter: mysql
database: wazi-radiant_production
username: root
password:
host: localhost</pre>
<p>That should do it for the configuration, now let&#8217;s bootstrap the application:</p>
<p style="30px;"><code>[freddy@wazi /usr/local/wazi-radiant]# jruby -S rake production db:bootstrap</code></p>
<pre style="30px;"><em>This task will destroy any data in the database. Are you sure you want to
continue? [yn] y</em></pre>
<pre style="30px;"><em>
= 1 CreateRadiantTables: migrating ==========================================Create the admin user (press enter for defaults).
Name (Administrator):
Username (admin):</em><em>Password (radiant):
Select a database template:
1. Empty
2. Simple Blog
3. Styled Blog</em><em>[1-3]: 3
Creating Pages....OK
Creating Layouts....OK
Creating Snippets....OK</em><em>Creating Page parts....OK
Finished.</em></pre>
<p>Now, let&#8217;s run a quick test to see if everything is where it should be. We will start WEBrick and open a test page:</p>
<pre style="30px;"><code>jruby -S script/server -e production -p 4444</code></pre>
<pre style="30px;">=&gt; Booting WEBrick...
=&gt; Rails application started on http://0.0.0.0:4444
=&gt; Ctrl-C to shutdown server; call with --help for options
[2008-11-19 16:29:03] INFO  WEBrick 1.3.1
[2008-11-19 16:29:03] INFO  ruby 1.8.6 (2008-11-03) [java]
[2008-11-19 16:29:03] INFO  WEBrick::HTTPServer#start: pid=3359 port=4444</pre>
<p>Pointing the browser to <code>http://localhost:4444/</code> should now result in a nice looking blog interface, with an admin section available at <code>http://localhost:4444/admin</code>.</p>
<p>Now, let&#8217;s install and configure GlassFish so that we can deploy this application in a Java engine.</p>
<a class="wazi-ad-link" href="http://www.openlogic.com/open-source-support.php "><img width="590" height="75" src="http://olex.openlogic.com/wazi/wp-content/uploads/2010/05/open-source-support-main.png" class="attachment-maincontent_ad" alt="Get open source software support" title="Get open source software support" /></a>
<h3>Installing GlassFish</h3>
<p>To install and configure GlassFish, you need to have <a title="JDK in OLEX" href="https://olex.openlogic.com/packages/jdk" target="_blank">JDK v5 or JDK v6</a> installed on your system. For this demo we are using JDK1.6.0_02-b05.</p>
<p>You can download the Glassfish v2-ur1-b09d installer from OLEX here https://olex.openlogic.com/packages/glassfish. And here are the instructions for running the installer:</p>
<blockquote><p>Make sure your JAVA_HOME is set to a <strong>JDK</strong>!</p>
<p>[freddy@wazi]# java -Xmx256m -jar filename.jar<br />
[freddy@wazi]# mv glassfish /usr/local/<br />
[freddy@wazi]# cd /usr/local/glassfish<br />
[freddy@wazi]# chmod -R +x lib/ant/bin<br />
[freddy@wazi]# lib/ant/bin/ant -f setup.xml<br />
We are waiting for <strong>BUILD SUCCESSFUL</strong></p></blockquote>
<p>Now you can move the Glassfish directory where you would like your Glassfish installation to live. ( Like /usr/local/glassfish )</p>
<p>Now cd into the glassfish directory and start the server&#8230;</p>
<p><code>[freddy@wazi]# bin/asadmin start-domain</code></p>
<pre style="30px;"><code>...</code></pre>
<pre style="30px;">Domain listens on at least following ports for connections:
[8080 8181 4848 3700 3820 3920 8686 ].
Domain does not support application server clusters and other standalone instances.</pre>
<p>You should now be able to access the GlassFish admin screen at <code>http://localhost:4848</code>, and the GlassFish landing page at <code>http://localhost:8080/<code>. The username/password for the admin console is admin/adminadmin.</code></code></p>
<p>We will now use Warbler to package our application into a war file, but we will need to setup the <code>warble.rb</code> configuration file first. First, we should create a generic configuration file for warbler. Strictly speaking, you don&#8217;t &#8220;need&#8221; a <code>wrble.rb</code> file, BUT it makes the process a lot easier, so we recommend it.</p>
<p style="30px;"><code>[freddy@wazi]# jruby -S warble config</code></p>
<p>The <code>warble.rb</code> file has a few issues with the Radiant <code>gem</code>, so we have to edit the file:</p>
<p style="30px;"><code>=&gt; config/warble.rb &lt;=</code></p>
<pre style="30px;">Warbler::Config.new do |config|
config.staging_dir = "tmp/war"
config.dirs = %w(config log vendor tmp)
config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"]
require "#{RAILS_ROOT}/config/boot"
BUILD_GEMS = %w(warbler rake rcov)
for gem in Gem.loaded_specs.values
next if BUILD_GEMS.include?(gem.name)
config.gems[gem.name] = gem.version.version
end
config.gem_dependencies = true
config.webxml.rails.env = ENV['RAILS_ENV'] || 'production'
end
[freddy@wazi /usr/local/wazi-radiant]# jruby -S warble
[freddy@wazi /usr/local/wazi-radiant]# ls *.war
wazi-radiant.war</pre>
<p>We now have a .war file that is deployable, so let&#8217;s push that to our running GlassFish server:</p>
<p style="30px;"><code>[freddy@wazi /usr/local/wazi-radiant]# ../glassfish/bin/asadmin deploy --contextroot / wazi-radiant.war</code></p>
<pre style="30px;"><code>Command deploy executed successfully.</code></pre>
<h2>Finishing Up</h2>
<p>Now our Radiant application can be accessed via <code>http://localhost:8080/</code>.</p>
<p>This was a very high level tutorial geared to get you up and running fast using Glassfish as your production Ruby on Rails server. We used a ready-to-deploy Rails application, Radiant, that drops into this environment easily and shows something &#8216;real&#8217; when the process is completed.</p>
]]></content:encoded>
			<wfw:commentRss>http://olex.openlogic.com/wazi/2008/jruby-and-glassfish-a-production-ruby-on-rails-environment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JRuby and Glassfish on Rails Part I: Setting Up A Developer Environment (on a Mac)</title>
		<link>http://olex.openlogic.com/wazi/2008/jruby-and-glassfish-as-a-rails-developer-environment/</link>
		<comments>http://olex.openlogic.com/wazi/2008/jruby-and-glassfish-as-a-rails-developer-environment/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 19:39:50 +0000</pubDate>
		<dc:creator>Freddy Andersen</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://olex.openlogic.com/wazi/?p=1452</guid>
		<description><![CDATA[In this tutorial, we cover setting up your Mac environment to use Glassfish as the server to run your Ruby on Rails projects. ]]></description>
			<content:encoded><![CDATA[<div style='padding:10px;border:1px solid;margin-bottom:20px;'>This article, <a href='http://olex.openlogic.com/wazi/2008/jruby-and-glassfish-as-a-rails-developer-environment/'>JRuby and Glassfish on Rails Part I: Setting Up A Developer Environment (on a Mac)</a>, originally appeared on <a
      href='http://olex.openlogic.com/wazi'>Wazi</a>, a free source for news, information, and articles on open source software.</div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2008%2Fjruby-and-glassfish-as-a-rails-developer-environment%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2008%2Fjruby-and-glassfish-as-a-rails-developer-environment%2F&amp;source=OpenLogic&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>In this tutorial, we&#8217;ll cover setting up your Mac environment to use <a title="GlassFish in OLEX" href="https://olex.openlogic.com/packages/glassfish" target="_blank">Glassfish</a> as the server to run your <a title="Ruby in OLEX" href="https://olex.openlogic.com/packages/ruby" target="_blank">Ruby</a> on <a title="Rails in OLEX" href="https://olex.openlogic.com/packages/rails" target="_blank">Rails</a> projects. This tutorial should port to a Linux desktop, but we&#8217;ve not tested that scenario.</p>
<h2>Before You Start</h2>
<p>There&#8217;s some stuff you&#8217;ll need on your system:</p>
<ul>
<li>MacPorts installed and at version 1.6. (http://www.macports.org/install.php )</li>
<li>Some diskspace.</li>
<li>About 15min.</li>
</ul>
<h2>Meat &amp; Potatoes</h2>
<h3>Installing JRuby</h3>
<p>The latest <a href="https://olex.openlogic.com/packages/jruby" target="_blank">JRuby</a>port is 1.1.3 so that is what we will use today.</p>
<p style="30px;"><code>[freddy@wazi]# port list jruby<br />
jruby           @1.1.3          lang/jruby</code></p>
<p>It&#8217;s as easy as entering:</p>
<p style="30px;"><code>[freddy@wazi]# sudo port install jruby<br />
[freddy@wazi]# ruby -v<br />
jruby 1.1.3 (ruby 1.8.6 patchlevel 114) (2008-11-17 rev 6586) [i386-java]</code></p>
<p><a title="JRuby in OLEX" href="https://olex.openlogic.com/packages/jruby" target="_blank">JRuby</a> uses a separate area to store <code>gems</code> and the Ruby environment, so we will need to install the <code>gems</code> that are needed for our development. This includes the Rails <code>gem</code>.</p>
<a class="wazi-ad-link" href="http://www.openlogic.com/open-source-support.php "><img width="590" height="75" src="http://olex.openlogic.com/wazi/wp-content/uploads/2010/05/open-source-support-main.png" class="attachment-maincontent_ad" alt="Get open source software support" title="Get open source software support" /></a>
<h3>Installing Rails and Friends</h3>
<p>Install <a title="Rails in OLEX" href="https://olex.openlogic.com/packages/rails" target="_blank">Rails</a> and create a test application:</p>
<p style="30px;"><code>[freddy@wazi]# sudo jruby -S gem install jruby-openssl<br />
[freddy@wazi]# sudo jruby -S gem install rails activerecord-jdbc-adapter<br />
[freddy@wazi]# sudo jruby -S rails wazi_app</code></p>
<p>Now we need to download the latest MySQL Java (JDBC) driver from https://olex.openlogic.com/packages/mysql-connector. Copy <code>mysql-connector-java-x.x.x-bin.jar</code> to <code>$JRUBY_HOME/lib</code> (/opt/local/share/java/jruby).</p>
<p>Now let&#8217;s update the <code>database.yml</code> file to use the JDBC driver:</p>
<pre style="30px;"><code>development:
adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/testapp_development
username: root
password:</code></pre>
<p>We should also make sure the JDBC driver will load. To do this, we edit the <code>environment.rb</code> file with these changes:</p>
<p style="30px;"><code><em><span style="italic;"># Bootstrap the Rails environment, frameworks, and default configuration</span><br />
<span style="italic;">require File.join(File.dirname(__FILE__), 'boot')</span></em><br />
<strong>if RUBY_PLATFORM =~ /java/<br />
require 'rubygems'<br />
RAILS_CONNECTION_ADAPTERS = %w(jdbc)<br />
end</strong></code></p>
<p>Now let&#8217;s boot the server in our JRuby environment:</p>
<p style="30px;"><code>[freddy@wazi]# jruby script/server<br />
=&gt; Booting WEBrick...<br />
=&gt; Rails 2.2.2 application started on http://0.0.0.0:4000<br />
=&gt; Ctrl-C to shutdown server; call with --help for options<br />
[2008-11-17 16:40:34] INFO  WEBrick 1.3.1<br />
[2008-11-17 16:40:34] INFO  ruby 1.8.6 (2008-11-17) [java]<br />
[2008-11-17 16:40:34] INFO  WEBrick::HTTPServer#start: pid=13484 port=4000</code></p>
<h3>Installing the Glassfish <code>gem</code></h3>
<p>Having <a title="GlassFish in OLEX" href="https://olex.openlogic.com/packages/glassfish" target="_blank">GlassFish</a> fully installed on your development environment is not always the best thing. If you don&#8217;t need it then you don&#8217;t want either the hogging of memory, or the administration that comes with a running J2EE container, so I&#8217;m going to show you an alternative. Do this:</p>
<p style="30px;"><code>[freddy@wazi]# jruby -S install glassfish</code></p>
<p>Whew, wasn&#8217;t that easy! <img src='http://olex.openlogic.com/wazi/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Now, let&#8217;s start the server using Glassfish rather than WEBrick:</p>
<p style="30px;"><code>[freddy@wazi]# jruby -S glassfish_rails<br />
...<br />
Nov 24, 2008 1:33:55 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start<br />
INFO: Listening on port 3000<br />
...<br />
Nov 24, 2008 1:34:01 PM com.sun.enterprise.v3.server.AppServerStartup run<br />
INFO: GlassFish v3 Prelude startup time : Felix(1813ms) startup services(6457ms) total(8270ms)</code><strong></strong></p>
<p style="30px;">
<p>Nice job! The application is now available at http://localhost:3000/.</p>
<h2>Finishing Up</h2>
<p>You now have a working environment in which you can develop your Rails application, and test them on your local desktop using a J2EE (<a title="GlassFish in OLEX" href="https://olex.openlogic.com/packages/glassfish" target="_blank">Glassfish</a>) container. We also installed<a title="JRuby in OLEX" href="https://olex.openlogic.com/packages/jruby" target="_blank"> JRuby</a> with all the required <code>gems</code> needed and this gives us the flexibility of either using JRuby or Ruby and/or Mongrel/Glassfish for different projects.</p>
<p style="30px;">As an added bonus, here&#8217;s some more information about the Glassfish gem:<br />
<code><br />
-c, --contextroot PATH: change the context root (default: '/')<br />
-p, --port PORT:        change server port (default: 3000)<br />
-e, --environment ENV:  change rails environment (default: development)<br />
-n --runtimes NUMBER:   Number of JRuby runtimes to crete initially<br />
--runtimes-min NUMBER:  Minimum JRuby runtimes to crete<br />
--runtimes-max NUMBER:  Maximum number of JRuby runtimes to crete<br />
APPLICATION_PATH (optional): Path to the application to be run (default: current)</code></p>
<p style="30px;">
<p style="30px;">
]]></content:encoded>
			<wfw:commentRss>http://olex.openlogic.com/wazi/2008/jruby-and-glassfish-as-a-rails-developer-environment/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
