<?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>Darren Nolan &#187; cPanel</title>
	<atom:link href="http://darrennolan.com/category/cpanel/feed/" rel="self" type="application/rss+xml" />
	<link>http://darrennolan.com</link>
	<description>Computer Tech... and stuff</description>
	<lastBuildDate>Mon, 10 Oct 2011 08:51:29 +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>cPanel + Redmine 1.2.1 &#8211; Pages delivered as text/plain when using rewrite</title>
		<link>http://darrennolan.com/2011/10/10/cpanel-redmine-1-2-1-pages-delivered-as-textplain-when-using-rewrite/</link>
		<comments>http://darrennolan.com/2011/10/10/cpanel-redmine-1-2-1-pages-delivered-as-textplain-when-using-rewrite/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 08:38:52 +0000</pubDate>
		<dc:creator>Dazz</dc:creator>
				<category><![CDATA[cPanel]]></category>
		<category><![CDATA[Redmine]]></category>

		<guid isPermaLink="false">http://darrennolan.com/?p=1008</guid>
		<description><![CDATA[Well. Bit more of a trouble than I wish to deal with today, but apparently Mongrel has changed somewhat in the latest version and doesn't deliver content as HTML, instead delivering it as text/plain (source html). If you are using Mongrel to deliver your Ruby Apps, and you're sure your versions of gems meet the [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fdarrennolan.com%2F2011%2F10%2F10%2Fcpanel-redmine-1-2-1-pages-delivered-as-textplain-when-using-rewrite%2F' data-shr_title='cPanel+%2B+Redmine+1.2.1+-+Pages+delivered+as+text%2Fplain+when+using+rewrite'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fdarrennolan.com%2F2011%2F10%2F10%2Fcpanel-redmine-1-2-1-pages-delivered-as-textplain-when-using-rewrite%2F' data-shr_title='cPanel+%2B+Redmine+1.2.1+-+Pages+delivered+as+text%2Fplain+when+using+rewrite'></a><a class='shareaholic-tweetbutton' data-shr_count='horizontal' data-shr_href='http%3A%2F%2Fdarrennolan.com%2F2011%2F10%2F10%2Fcpanel-redmine-1-2-1-pages-delivered-as-textplain-when-using-rewrite%2F' data-shr_title='cPanel+%2B+Redmine+1.2.1+-+Pages+delivered+as+text%2Fplain+when+using+rewrite'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Well.</p>

<p>Bit more of a trouble than I wish to deal with today, but apparently Mongrel has changed somewhat in the latest version and doesn't deliver content as HTML, instead delivering it as text/plain (source html).</p>

<p>If you are using Mongrel to deliver your Ruby Apps, and you're <strong>sure</strong> your versions  of gems meet the <a href="http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Compatibility-notes" target="_blank">requirements </a> - take a look at the below to try.</p>

<p>Add this file in, restart your application - and hopefully away you go.  Again there is a lot of read/take in when it comes to dealing with this issue - hopefully I'm saving you about 1.5 hours of <a href="https://rails.lighthouseapp.com/projects/8994/tickets/4690#ticket-4690-23" target="_blank">research.</a> <a href="https://gist.github.com/471663" target="_blank">Original Source for the Patch I've forked.</a>.</p>

<p>Add this to redmine/config/initializers/mongrel.rb (create a new file)</p>
<pre class="brush: ruby; title: ; notranslate">
# Pulled right from latest rack. Old looked like this in 1.1.0 version.
  # 
  # def [](k)
  #   super(@names[k] ||= @names[k.downcase])
  # end
  # 
  module Rack
    module Utils
      class HeaderHash &lt; Hash
        def [](k)
          super(@names[k]) if @names[k]
          super(@names[k.downcase])
        end
      end
    end
  end
  
  # Code pulled from the ticket above.
  # 
  class Mongrel::CGIWrapper
    def header_with_rails_fix(options = 'text/html')
      @head['cookie'] = options.delete('cookie').flatten.map { |v| v.sub(/^\n/,'') } if options.class != String and options['cookie']
      header_without_rails_fix(options)
    end
    alias_method_chain :header, :rails_fix
  end
  
  # Pulled right from 2.3.8 ActionPack. Simple diff was
  # 
  # if headers.include?('Set-Cookie')
  #   headers['cookie'] = headers.delete('Set-Cookie').split(&quot;\n&quot;)
  # end
  # 
  # to 
  # 
  # if headers['Set-Cookie']
  #   headers['cookie'] = headers.delete('Set-Cookie').split(&quot;\n&quot;)
  # end
  #       
  module ActionController
    class CGIHandler
      def self.dispatch_cgi(app, cgi, out = $stdout)
        env = cgi.__send__(:env_table)
        env.delete &quot;HTTP_CONTENT_LENGTH&quot;
        cgi.stdinput.extend ProperStream
        env[&quot;SCRIPT_NAME&quot;] = &quot;&quot; if env[&quot;SCRIPT_NAME&quot;] == &quot;/&quot;
        env.update({
          &quot;rack.version&quot; =&gt; [0,1],
          &quot;rack.input&quot; =&gt; cgi.stdinput,
          &quot;rack.errors&quot; =&gt; $stderr,
          &quot;rack.multithread&quot; =&gt; false,
          &quot;rack.multiprocess&quot; =&gt; true,
          &quot;rack.run_once&quot; =&gt; false,
          &quot;rack.url_scheme&quot; =&gt; [&quot;yes&quot;, &quot;on&quot;, &quot;1&quot;].include?(env[&quot;HTTPS&quot;]) ? &quot;https&quot; : &quot;http&quot;
        })
        env[&quot;QUERY_STRING&quot;] ||= &quot;&quot;
        env[&quot;HTTP_VERSION&quot;] ||= env[&quot;SERVER_PROTOCOL&quot;]
        env[&quot;REQUEST_PATH&quot;] ||= &quot;/&quot;
        env.delete &quot;PATH_INFO&quot; if env[&quot;PATH_INFO&quot;] == &quot;&quot;
        status, headers, body = app.call(env)
        begin
          out.binmode if out.respond_to?(:binmode)
          out.sync = false if out.respond_to?(:sync=)
          headers['Status'] = status.to_s
          if headers['Set-Cookie']
            headers['cookie'] = headers.delete('Set-Cookie').split(&quot;\n&quot;)
          end
          out.write(cgi.header(headers))
          body.each { |part|
            out.write part
            out.flush if out.respond_to?(:flush)
          }
        ensure
          body.close if body.respond_to?(:close)
        end
      end
    end
  end
</pre>


<div class="shr-publisher-1008"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://darrennolan.com/2011/10/10/cpanel-redmine-1-2-1-pages-delivered-as-textplain-when-using-rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Redmine on a cPanel server &#8211; Silly .htaccess rules</title>
		<link>http://darrennolan.com/2010/05/23/using-redmine-on-a-cpanel-server-silly-htaccess-rules/</link>
		<comments>http://darrennolan.com/2010/05/23/using-redmine-on-a-cpanel-server-silly-htaccess-rules/#comments</comments>
		<pubDate>Sun, 23 May 2010 05:19:11 +0000</pubDate>
		<dc:creator>Dazz</dc:creator>
				<category><![CDATA[cPanel]]></category>
		<category><![CDATA[Redmine]]></category>
		<category><![CDATA[subdirectory]]></category>
		<category><![CDATA[subdomain]]></category>

		<guid isPermaLink="false">http://www.darrennolan.com/?p=83</guid>
		<description><![CDATA[It's not nearly has hard when you know what the hell you're doing.  Oh by the way, that's not the case with me &#60;_&#60;  Find an installation guide elsewhere (or even adapt the actual installation guide from Redmine).  This guide is manually how to setup rewrite rules properly so you can use Redmine as ether [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fdarrennolan.com%2F2010%2F05%2F23%2Fusing-redmine-on-a-cpanel-server-silly-htaccess-rules%2F' data-shr_title='Using+Redmine+on+a+cPanel+server+-+Silly+.htaccess+rules'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fdarrennolan.com%2F2010%2F05%2F23%2Fusing-redmine-on-a-cpanel-server-silly-htaccess-rules%2F' data-shr_title='Using+Redmine+on+a+cPanel+server+-+Silly+.htaccess+rules'></a><a class='shareaholic-tweetbutton' data-shr_count='horizontal' data-shr_href='http%3A%2F%2Fdarrennolan.com%2F2010%2F05%2F23%2Fusing-redmine-on-a-cpanel-server-silly-htaccess-rules%2F' data-shr_title='Using+Redmine+on+a+cPanel+server+-+Silly+.htaccess+rules'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>It's not nearly has hard when you know what the hell you're doing.  Oh by the way, that's not the case with me &lt;_&lt;  Find an installation guide elsewhere (or even adapt the actual installation guide from Redmine).  This guide is manually how to setup rewrite rules properly so you can use Redmine as ether a proper subdomain entry (redmine.yourdomain.com) or even slightly more tricky, as a subdomain entry (www.yourdomain.com/redmine).  Sadly cPanel htaccess rules generated from their interface ... suck.  Pretty badly &gt;_&gt;  No idea why.</p>

<p>MOVING ON.</p>

<p><span style="text-decoration: underline;"><strong>Bit 1</strong></span><br>
Go into cPanel -&gt; Ruby on Rails<br>
Create a new application by entering the application name.  Be happy with the default location it will store your application (/rails_apps/redmine for example)<br>
Ensure it's going to start when someone reboots the server on you (sif  they'd do that anyway).  Tick "Load on Boot".<br>
Don't bother starting the application yet.<br>
Find out which port you've been assigned - click "URL" and you should be taken to a page that can not be displayed - you'll see something like http://yourdomain:PORTNUMBER - the portnumber folks is important.<br>
</p>

<p><span style="text-decoration: underline;"><strong>Bit 2</strong></span><br>
Go into cPanel -&gt; MySQL databases<br>
Generate a new database, a new username/password and ensure you assign the new user to the database we just created.<br>
</p>

<p><span style="text-decoration: underline;"><strong>Bit 3</strong></span><br>
Get into shell or FTP (whatever is available to you) and remove everything that's pre-generated under ~/rails_apps/redmine<br>
Extract the latest redmine application source and put it in that folder we just cleaned out.<br>
Copy config/database.yml.example to config/database.yml<br>
Edit that file, change the stuff about production and what your MySQL details are (seek the real installation for more info - <a href="http://www.redmine.org/wiki/redmine/RedmineInstall">http://www.redmine.org/wiki/redmine/RedmineInstall</a>)Also following that installation guide, ensure you do the following parts<br>
Get into shell as your cpanel user and enter the following funky stuffs;
</p>
<pre class="brush: bash; title: ; notranslate">
cd ~/rails_app/redmine
RAILS_ENV=production rake config/initializers/session_store.rb
RAILS_ENV=production rake redmine:load_default_data
</pre>

<p><span style="text-decoration: underline;"><strong>Bit 4</strong></span><br>
In cPanel -&gt; Ruby Applications, you can go ahead and start the server now.</p>

<p>Now here comes the main part of this little installation guide (there are more completed installation guides out there on the web guys.</p>

<p><span style="text-decoration: underline;"><strong>THE IMPORTANT HTACCESS REWRITE BIT</strong></span></p>
<p>Wherever your "public" html access is, go there and create a .htaccess file.  For example if redmine is being put in your main domain's location, your location will be ~/public_html/.htacces - if it's a subdomain it's typically ~/public_html/subdomain/.htaccess unless you specified otherwise (which I always recomment... shoving subdomains under another domains document root is tacky, especially when dealing with .htaccess)</p>

<p>For "Whole" domain/subdomain (http://redmine.yourdomain.com) installations, put in the following text in the htaccess file</p>

<pre class="brush: plain; title: ; notranslate">
RewriteEngine on
RewriteCond %{HTTP_HOST} ^redmine.yourdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.redmine.yourdomain.com$
RewriteRule ^.*$ &quot;http\:\/\/127\.0\.0\.1\:12001%{REQUEST_URI}&quot; [P,QSA,L]
</pre>

<p>The two RewriteCond(itions) there are limiting this to the subdomain redmine.  If you aren't playing with a subdomain you can actually remove those two lines.
This htaccess example is "pretty much" what cPanel generates at time of writing, minus the "^.*$" part, for whatever reason they're still having ? inserted in there which naturally, causes headaches.</p>

<p>Now the uber tricky part.  You want it to be http://www.yourdomain.com/redmine - a "directory".<br>
First up - edit ~/rails_apps/redmine/config/environment.rb and at the very end of the file (even after the "end" part) add the following</p>
<pre class="brush: plain; title: ; notranslate">Redmine::Utils::relative_url_root = &quot;/redmine&quot;</pre>

<p>In your htaccess file, you'll want to do the following.</p>

<pre class="brush: plain; title: ; notranslate">
RewriteEngine On
RewriteRule ^redmine$ http://localhost:12002/$1 [P,QSA,L]
RewriteRule ^redmine/(.*)$ http://localhost:12002/$1 [P,QSA,L]
</pre>

<p>Again, ignoring the Rewrite conditions if you aren't setting up /redmine on a subdomain.</p>

<p>Notice where the 12001 part is in the htaccess files, you'll want to change that to whatever port number cPanel has set your redmine application to.</p>

<p>Edit: Updated htaccess rule for the subdirectory.  It appears that despite my efforts redmine would only work if there was a trailing slash.  Without it, it wasn't working.  Then I got it working the other way around....  and now... I have two rules... not ideal but it's working again.  \o/</p><div class="shr-publisher-83"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://darrennolan.com/2010/05/23/using-redmine-on-a-cpanel-server-silly-htaccess-rules/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

