<?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>info.michael-simons.eu &#187; Apache</title>
	<atom:link href="http://info.michael-simons.eu/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://info.michael-simons.eu</link>
	<description>Just another nerd blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:26:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Apache httpd, Tomcat und sendfile</title>
		<link>http://info.michael-simons.eu/2011/06/28/apache-httpd-tomcat-und-sendfile/</link>
		<comments>http://info.michael-simons.eu/2011/06/28/apache-httpd-tomcat-und-sendfile/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 08:47:04 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[NIO]]></category>
		<category><![CDATA[sendfile]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=518</guid>
		<description><![CDATA[I used to use mod_xsendfile by Nils Maier, who&#8217;s Homepage doesn&#8217;t seem to exist anymore, to send files from Ruby proxied by Apache respectively powered by modrails. Those files shouldn&#8217;t be in any public www directory as authorization needs to be checked, but are accessed very often so that streaming them is not an option. [...]]]></description>
			<content:encoded><![CDATA[<p>I used to use <em>mod_xsendfile</em> by Nils Maier, who&#8217;s Homepage doesn&#8217;t seem to exist anymore, to send files from Ruby proxied by Apache respectively powered by modrails. Those files shouldn&#8217;t be in any public www directory as authorization needs to be checked, but are accessed very often so that streaming them is not an option. </p>
<p>To use this technique you need <a href="http://info.michael-simons.eu/wp-content/uploads/2011/06/mod_xsendfile.c">mod_xsendfile</a>, which is attached to this post.</p>
<p>I just have rewritten my application from Ruby on Rails to Java and it&#8217;s easy to add the necessary headers in a HttpServletResponse:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;X-Sendfile&quot;</span>, file.<span style="color: #006633;">getAbsolutePath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
response.<span style="color: #006633;">flushBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You may add other headers like Content-Type and the like but you must not modify the body, hence the flushBuffer.</p>
<p>This works quite well&#8230; As long as had my Apache httpd running with mpm-prefork.</p>
<p>Switching to Apache mpm-worker caused some problems. I cannot say with a final conclusion that mod_xsendfile was causing troubles but i started to see the wrong files (images in this case) delivered or not delivered at all.</p>
<p>My alternate solution was streaming the files using Channels from java.nio but CPU usage went nuts. </p>
<p>The solution now employed is the using Apache Tomcats asynchronous writes that are available since Tomcat 6. Their documentation is rather <a href="http://tomcat.apache.org/tomcat-6.0-doc/aio.html">short</a> but so is implementing them:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
HttpServletRequest request = ...
HttpServletResponse response = ...
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>request <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #003399;">Boolean</span>.<span style="color: #000066; font-weight: bold;">TRUE</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;org.apache.tomcat.sendfile.support&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>		
  <span style="color: #000066; font-weight: bold;">long</span> l <span style="color: #339933;">=</span> file.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  request.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;org.apache.tomcat.sendfile.filename&quot;</span>, absolutePath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  request.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;org.apache.tomcat.sendfile.start&quot;</span>, 0l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  request.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;org.apache.tomcat.sendfile.end&quot;</span>, l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Length&quot;</span>, <span style="color: #003399;">Long</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  response.<span style="color: #006633;">flushBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>use_xsendfile<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// see above</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// stream files</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What i got wrong at first was setting those attributes in the response. That didn&#8217;t work. The must be set in the request and you must take care setting all of those and with the correct type (String respectively long). And that&#8217;s it.</p>
<p>The request attribute <strong>org.apache.tomcat.sendfile.support</strong> will be true when the connector is configured to either use the <strong>APR connector</strong> (org.apache.coyote.http11.Http11AprProtocol) or the <strong>non blocking Java connector</strong> (org.apache.coyote.http11.Http11NioProtocol) (the later one being easier  to deploy as it has no external dependencies).</p>
<p>CPU usage for sending those files is now nearly 0.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=518&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_518" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2011/06/28/apache-httpd-tomcat-und-sendfile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress 2.2 Update</title>
		<link>http://info.michael-simons.eu/2007/05/17/wordpress-22-update/</link>
		<comments>http://info.michael-simons.eu/2007/05/17/wordpress-22-update/#comments</comments>
		<pubDate>Thu, 17 May 2007 11:24:15 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[janb]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/2007/05/17/wordpress-22-update/</guid>
		<description><![CDATA[Wordpress 2.2 arrived a day ago. Updating was no problem at all. Prominent new features are wigdet support without the need for an external plugin and a working atom 1.0 feed. I could drop two plugins: the widget plugin and the atom10 plugin. Nice. All others work as before (some important to mention are UTW, [...]]]></description>
			<content:encoded><![CDATA[<p>
Wordpress 2.2 arrived a day ago.<br />
Updating was no problem at all. Prominent new features are wigdet support without the need for an external plugin and a working atom 1.0 feed.</p>
<p>I could drop two plugins: the widget plugin and the atom10 plugin. Nice. All others work as before (some important to mention are UTW, WP-Cache and the nice extended live archive(*).</p>
<p>A really nice site effect of the update: the WP Team finally managed to put a &#8220;SET NAMES blah&#8221; into wp-db.php, so that setting &#8220;UTF-8&#8243; i.e. in wp-admin really means UTF-8 in the database. I always hacked my wp-db(**) for my other blog <a href="http://planet-punk.de">planet-punk.de</a>, since there are a lot of old posts from another legacy system that _are_ indeed UTF-8 but which where maltransformed by wp without that hack before 2.2.</p>
<p>I do have a local development system on my mac but i tend to test things twice or more often. Other people maybe don&#8217;t have or want that luxury and need to udate their blogs directly on the server. Either way, it&#8217;s a good idea, to put your blog to maintenance while updating your wp core files. This is easily accomplished with .htacess and mod_rewrite. First create a file &#8220;maintenance.html&#8221; for your visitors. Than look up your external ip and add the following to your .htaccess:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_rewrite.c&gt;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteCond</span> %{REMOTE_ADDR} !87.78.68.17 [NC]
<span style="color: #00007f;">RewriteRule</span> ! maintenance.html$ maintenance.html [R=<span style="color: #ff0000;">301</span>,L]
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</pre></div></div>

<p>and replace 87.78.68.17 with your external ip. Remember commenting these entries when you&#8217;re done.</p>
<p><small>(*) If you have any questions about my plugins, don&#8217;t hesitate to ask, i just don&#8217;t want a plugin list in case of bugs in any plugin.</small></p>
<p><small>(**) The hack <em>was</em>: Add the following to <em>__construct</em> in your wp-db.php (./wp-includes/) :</small></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET NAMES 'utf8'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p class="akst_link"><a href="http://info.michael-simons.eu/?p=78&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_78" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2007/05/17/wordpress-22-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails mit FastCGI und Apache unter Mac OS X</title>
		<link>http://info.michael-simons.eu/2006/06/28/rails-mit-fastcgi-und-apache-unter-mac-os-x/</link>
		<comments>http://info.michael-simons.eu/2006/06/28/rails-mit-fastcgi-und-apache-unter-mac-os-x/#comments</comments>
		<pubDate>Wed, 28 Jun 2006 09:59:03 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://www.msimons.info/?p=26</guid>
		<description><![CDATA[Die vorherigen Artikel Ruby on Rails mit Mac OS X und Rails: Rolling into production on Mac OS X beschäftigten sich mit der Installation von Ruby on Rails unter Mac OS X bzw. mit der Produktivumgebung von Rails. Prämisse für mich war jedesmal, dass der eingebaute Mac OS X Apache genutzt wird und nicht ein [...]]]></description>
			<content:encoded><![CDATA[<p>Die vorherigen Artikel <a href="http://info.michael-simons.eu/?p=17">Ruby on Rails mit Mac OS X</a> und <a href="http://info.michael-simons.eu/?p=22">Rails: Rolling into production on Mac OS X</a> beschäftigten sich mit der Installation von Ruby on Rails unter Mac OS X bzw. mit der Produktivumgebung von Rails.</p>
<p>Prämisse für mich war jedesmal, dass der eingebaute Mac OS X Apache genutzt wird und nicht ein zweiter Serverprozess.</p>
<p>Heute soll es um die FastCGI Integration gehen. CGI war mir bis jetzt zum Testen nicht zu langsam. Fängt man aber mit AJAX Spielerein an und nutzt Rails mit CGI, kann man das auch getrost ganz sein lassen. Vorweg: FastCGI zu CGI ist ein Unterschied wie Tag und Nacht.</p>
<p>Was braucht man? (Die Links verweisen direkt auf die benötigten Dateien)</p>
<ul>
<li><a href="http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz">FastCGI SDK</a></li>
<li><a href="http://www.fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz">mod_fastcgi für Apache 1.3</a></li>
<li><a href="http://sugi.nemui.org/pub/ruby/fcgi/ruby-fcgi-0.8.6.tar.gz">Ruby Bindings für FastCGI</a></li>
</ul>
<p>Die Installation ist relativ einfach.</p>
<p>FastCGI SDK:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>mod_fastcgi</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">apxs <span style="color: #660033;">-o</span> mod_fastcgi.so <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">*</span>.c 
<span style="color: #c20cb9; font-weight: bold;">sudo</span> apxs <span style="color: #660033;">-i</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> fastcgi mod_fastcgi.so</pre></div></div>

<p>Ruby Bindings</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ruby install.rb config
ruby install.rb setup
ruby install.rb <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Fast geschafft. Es folgt ein Apache Neustart mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> apachectl graceful</pre></div></div>

<p>Anschliessend gibt es einen kleinen Pitfall. Man muss zwei Tempverzeichnisse für FastCGI chmoden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">777</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>fcgi_ipc
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">777</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>fcgi_ipc<span style="color: #000000; font-weight: bold;">/</span>dynamic</pre></div></div>

<p>sonst geht es in die Hose.</p>
<p>Anschliessend zur Apache Konfiguration. Diese habe ich wieder auf zwei Dateien aufgeteilt. In der httpd.conf wird das Modul mod_fastcgi geladen. Der Installer hat diesen Eintrag bereits automatisch erzeugt. Wenn nicht, folgende Zeilen ergänzen:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">LoadModule</span> fastcgi_module     libexec/httpd/mod_fastcgi.so</pre></div></div>

<p>Danach den Handler einrichten:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_fastcgi.c&gt; 
FastCgiIpcDir /tmp/fcgi_ipc/ 
<span style="color: #00007f;">AddHandler</span> fastcgi-<span style="color: #00007f;">script</span> .fcgi 
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</pre></div></div>

<p>und wir sind fast fertig. Die eigentliche Rails Anwendung wird wieder in der Userspezifischen httpd.conf eingestellt, zu finden unter /etc/httpd/users/name.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_fastcgi.c&gt;
   FastCgiServer <span style="color: #7f007f;">&quot;/Users/msimons/dev/rails/test/public/dispatch.fcgi&quot;</span> -
initial-env RAILS_ENV=production -processes <span style="color: #ff0000;">15</span> -idle-<span style="color: #00007f;">timeout</span> <span style="color: #ff0000;">60</span>
&lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;</pre></div></div>

<p>Die Werte fürs Timeout und die Anzahl Prozesse sind aus dem Buch &#8220;Agile Web Development with Rails&#8221;.</p>
<p>Die Anwendung nutzt fastcgi, sobald man die entsprechende Rewrite Rule in .htaccess im public folder setzt:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteRule</span> ^(.*)$ dispatch.fcgi [QSA,L]</pre></div></div>

<p>bzw. die ursprüngliche Regel
<pre>RewriteRule ^(.*)$ dispatch.cgi [QSA,L]</pre>
<p> ändert.</p>
<p>Danach ist ein letzter Apache Neustart fällig und man sieht seine Anwendung auf einmal in einem ganz anderen Tempo.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=26&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_26" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2006/06/28/rails-mit-fastcgi-und-apache-unter-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails: Rolling into production on Mac OS X</title>
		<link>http://info.michael-simons.eu/2006/05/29/rails-rolling-into-production-on-mac-os-x/</link>
		<comments>http://info.michael-simons.eu/2006/05/29/rails-rolling-into-production-on-mac-os-x/#comments</comments>
		<pubDate>Mon, 29 May 2006 20:57:20 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Tipps]]></category>

		<guid isPermaLink="false">http://www.msimons.info/?p=22</guid>
		<description><![CDATA[Damit die SetEnv RAILS_ENV production Direktive in der httpd.conf oder einer lokalen .htaccess Datei funktioniert, muss das Modul &#8220;env_module&#8221; im Apache aktiviert werden. Dies wird unter Mac OS X nicht standardmässig getan. Folgende Zeilen in der /etc/httpd.conf einkommentieren: LoadModule env_module libexec/httpd/mod_env.so AddModule mod_env.c Share This]]></description>
			<content:encoded><![CDATA[<p>Damit die</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">SetEnv</span> RAILS_ENV production</pre></div></div>

<p>Direktive in der httpd.conf oder einer lokalen .htaccess Datei funktioniert, muss das Modul &#8220;env_module&#8221; im Apache aktiviert werden. Dies wird unter Mac OS X nicht standardmässig getan. </p>
<p>Folgende Zeilen in der /etc/httpd.conf einkommentieren:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">LoadModule</span> env_module         libexec/httpd/mod_env.so
<span style="color: #00007f;">AddModule</span> mod_env.c</pre></div></div>

<p class="akst_link"><a href="http://info.michael-simons.eu/?p=22&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_22" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2006/05/29/rails-rolling-into-production-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails mit Mac OS X</title>
		<link>http://info.michael-simons.eu/2006/05/05/ruby-on-rails-mit-mac-os-x/</link>
		<comments>http://info.michael-simons.eu/2006/05/05/ruby-on-rails-mit-mac-os-x/#comments</comments>
		<pubDate>Fri, 05 May 2006 16:51:23 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Lesetipps]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.msimons.info/?p=17</guid>
		<description><![CDATA[Nachdem mich die Tutorials bzw. die kurzen Videos auf rubyonrails.org sehr begeistert haben, musste ich natürlich direkt Rails ausprobieren. Für den Einstieg sind die diversen Tutorials, die man im Netz findet, recht interessant, wirklich gut ist aber das Buch Agile Web Development with Rails. Man sollte darauf achten, dass man die zweite Ausgabe kauft und [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem mich die Tutorials bzw. die kurzen Videos auf <a href="http://www.rubyonrails.org" rel="external">rubyonrails.org</a> sehr begeistert haben, musste ich natürlich direkt Rails ausprobieren.</p>
<p>Für den Einstieg sind die diversen Tutorials, die man im Netz findet, recht interessant, wirklich gut ist aber das Buch <a href="http://www.pragmaticprogrammer.com/titles/rails/index.html" rel="external">Agile Web Development with Rails</a>. Man sollte darauf achten, dass man die zweite Ausgabe kauft und nicht wie ich die erste über Amazon.</p>
<p>Im Buch steht soweit alles drin, was man tun muss, um unter Mac OS X direkt loszulegen. Seit OS X Tiger in der Version 10.4.6 funktioniert auch die mitgelieferte Ruby Version problemlos mit Rails. </p>
<p>Um Rails zu installieren sind folgende Schritte notwendig:</p>
<h2>RubyGems</h2>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5207</span><span style="color: #000000; font-weight: bold;">/</span>rubygems-0.8.11.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf rubygems-0.8.11.tgz
<span style="color: #7a0874; font-weight: bold;">cd</span> rubygems-0.8.11
<span style="color: #c20cb9; font-weight: bold;">sudo</span> ruby setup.rb</pre></div></div>

<h2>Rails</h2>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails <span style="color: #660033;">--include-dependencies</span></pre></div></div>

<p>FastCGI bzw. LightTPD habe ich übersprungen, brauche ich zur Zeit nicht. Allerdings muss natürlich eine Datenbank her. Da ich bereits seit langem MySQL auf dem Rechner habe, wollte ich das auch nutzen:</p>
<h2>MySQL</h2>
<p>MySQL war der einzige Punkt, der etwas kritisch war. Die folgenden Befehle müssen natürlich an den Installationsort von MySQL angepasst werden, in den meisten Fällen wird der MySQL Installer allerdings einen Link nach /user/local/mysql erzeugt haben.</p>
<p>Folgender Befehl versagte bei mir:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql <span style="color: #660033;">--</span> <span style="color: #660033;">--with-mysql-dir</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql</pre></div></div>

<p>Und ich sah die ganze Zeit nur:</p>
<pre>
no checking for main() in -lm...
yes checking for mysql_query() in -lmysqlclient...
no checking for main() in -lz...
yes checking for mysql_query() in -lmysqlclient...
no checking for main() in -lsocket...
no checking for mysql_query() in -lmysqlclient...
no checking for main() in -lnsl...
no checking for mysql_query() in -lmysqlclient...
</pre>
<p>Geholfen hat die explizite Angabe der Libraries und Headerverzeichnisse wie folgt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql <span style="color: #660033;">--</span> <span style="color: #660033;">--with-mysql-include</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">--with-mysql-lib</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Danach lief Rails mit dem eingebauten WEBrick problemlos.</p>
<h2>Der eingebaute Apache unter Mac OS X</h2>
<p>Für fertige Applikationen will ich den eingebauten Apache von OS X nutzen. Auch dazu gibt es einige Tutorials, aber keines alleine führte zu einer funktionierenden, sinnvollen Konfiguration.<br />
Ich bin gewohnt, dass ich meine Seiten auf meinem Rechner unter http://localhost/~msimons/blah erreiche und das wollte ich auch mit den Railsanwendungen können.</p>
<p>Der Mac OS X Apache ist in meinen Augen für einen Rechner, der nicht direkt im Internet hängt, sehr sinnvoll konfiguriert, ich wollte deshalb nicht in der zentralen httpd.conf rumpfuschen. Praktischerweise legt OS X unter /etc/httpd/users/ für jeden OS User eine weitere conf Datei an, die ich entsprechend anpasse. Dazu habe ich mir einen Link auf dieses Datei erstellt und den Eigentümter von root auf mich geändert.</p>
<p>Für eine Beispielapplikation sieht das dann so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">Alias</span> /~msimons/test/  <span style="color: #7f007f;">&quot;/Users/msimons/dev/rails/test/public/&quot;</span>
<span style="color: #00007f;">Alias</span> /~msimons/test   <span style="color: #7f007f;">&quot;/Users/msimons/dev/rails/test/public/&quot;</span>
&nbsp;
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;/Users/msimons/dev/rails/test/public/&quot;</span>&gt;
    <span style="color: #00007f;">Options</span> ExecCGI <span style="color: #0000ff;">FollowSymLinks</span>
    <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">all</span>
    <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
    <span style="color: #00007f;">Allow</span> from <span style="color: #0000ff;">all</span>
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;</pre></div></div>

<p>Danach muss die .htaccess Datei im public Verzeichnis der Testanwendung angepasst werden:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /~msimons/test/</pre></div></div>

<p>Die forwardslashes sind essentiell.</p>
<p>Ich hatte <a href="http://tonyarnold.com/articles/2005/08/10/rolling-with-ruby-on-rails-on-mac-os-x-tiger-for-beginners" rel="external">hier</a> Hinweise gefunden, dass man in einigen Verzeichnissen noch Rechte anpassen muss, weil Apache natürlich nicht im Kontext des Benutzers läuft, sondern unter www:</p>
<p>Deswegen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rails<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chgrp</span> <span style="color: #660033;">-R</span> www Test
<span style="color: #7a0874; font-weight: bold;">cd</span> Test
<span style="color: #c20cb9; font-weight: bold;">chmod</span> 0775 db
<span style="color: #c20cb9; font-weight: bold;">chmod</span> 0777 log
<span style="color: #c20cb9; font-weight: bold;">chmod</span> 0775 public
<span style="color: #c20cb9; font-weight: bold;">chmod</span> 0666 log<span style="color: #000000; font-weight: bold;">/*</span>.log</pre></div></div>

<p>Allerdings wurde dabei das tmp Verzeichnis vergessen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> 0775 tmp</pre></div></div>

<p>Nach einem kurzen Apache Neustart über die Systemeinstellungen oder per</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> apachectl graceful</pre></div></div>

<p>steht dem Railsvergnügen unter OS X nichts mehr im Wege.</p>
<h2>Resourcen</h2>
<p>Geholfen haben mir unter anderem:</p>
<ul>
<li><a href="http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger" rel="external">Building Ruby, Rails, LightTPD, and MySQL on Tiger</a></li>
<li><a href="http://tonyarnold.com/articles/2005/08/10/rolling-with-ruby-on-rails-on-mac-os-x-tiger-for-beginners" rel="external">Rolling with ruby on rails on mac os x tiger for beginners</a></li>
<li><a href="http://wiki.rubyonrails.com/rails/pages/HowtoInstallOnOSXTiger" rel="external">HowtoInstallOnOSXTiger</a></li>
<li><a href="http://www.macdevcenter.com/pub/a/mac/2006/03/29/rails.html" rel="external">Bringing Ruby on Rails with FastCGI into Mac OS X Server</a></li>
</ul>
<p>Gute Bücher gibt es hier: <a href="http://www.pragmaticprogrammer.com" rel="external">The Pragmatic Programmer</a>. Sehr empfehlenswert <a href="http://www.pragmaticprogrammer.com/titles/rails/index.html" rel="external">Agile Web Development with Rails</a> und <a href="http://www.pragmaticprogrammer.com/titles/ruby/index.html">Programming Ruby</a>. Wenn man ersteres kauft, gibt es auf jedes Ruby Buch Rabatt. Sehr charmant.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=17&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_17" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2006/05/05/ruby-on-rails-mit-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.636 seconds -->

