# FCGI example setup for Apache + Ruby on Rails

**URL:** <https://www.ruby-forum.com/t/fcgi-example-setup-for-apache-ruby-on-rails/253185>\
**Category:** Deployment\
**Created:** [October 10, 2019, 8:44am UTC](https://www.ruby-forum.com/t/fcgi-example-setup-for-apache-ruby-on-rails/253185 "2019-10-10T08:44:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KlausFriese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@KlausFriese](https://www.ruby-forum.com/u/KlausFriese)\
**Post date:** [October 10, 2019, 8:44am UTC](https://www.ruby-forum.com/t/fcgi-example-setup-for-apache-ruby-on-rails/253185/1 "2019-10-10T08:44:45Z")

</div>

Hi,

first post in the forum, I hope I found the right category.

I try to set up an redmine installation on an managed server with linux/apache, I’m not very familiar with ruby and rails.

I managed to install all the gems and following the install guide I finished the installation. Redmine works with the webrick server.

No I have problems with the FCGI integration, I always get an Error 500. I followed the instructions from my hosting company and the redmine docs - no success.

So the next step is to create a simple “hello world” ruby/rails/fcgi/apache test application.

My .htaccess is:  
AddHandler fcgid-script .fcgi

```
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

```

my dispatch.fcgi is:  
#!/bin/dash  
export GEM\_HOME="$HOME/.gem/ruby/2.3.0/"  
export GEM\_PATH="$GEM\_HOME:/var/lib/ruby/gems/1.8"  
exec /usr/bin/ruby /usr/www/users/admin/test/hello.rb

And hello.rb:  
puts ‘Hello World!’

Didn’t work, I got the Error 500. What’s wrong or missing?

Thanks for any tipps  
Klaus

---

<div class="post-metadata">

**Author:** ![Maniac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/13edae/32.png) [@Maniac](https://www.ruby-forum.com/u/Maniac)\
**Post date:** [October 16, 2019, 7:07pm UTC](https://www.ruby-forum.com/t/fcgi-example-setup-for-apache-ruby-on-rails/253185/2 "2019-10-16T19:07:20Z")

</div>

Hey Klaus,

Check the REDMINE\_ROOT/log/ **production.log** and if that information couldn’t help you, please provide its content here.

---

<div class="post-metadata">

**Author:** ![KlausFriese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/71e660/32.png) [@KlausFriese](https://www.ruby-forum.com/u/KlausFriese)\
**Post date:** [April 6, 2020, 7:51am UTC](https://www.ruby-forum.com/t/fcgi-example-setup-for-apache-ruby-on-rails/253185/3 "2020-04-06T07:51:17Z")

</div>

Sorry for the late reply - no entries in the production log, it failed before logging.

But with much time and help from my provider I solved this. If anyone in the future has the same problem - here is my configuration:

**.htaccess** is:

> FcgidWrapper /usr/www/users/admin/redmine/ruby\_handler.fcgi .rb  
> RewriteEngine On  
> RewriteRule ^$ index.html [QSA]  
> RewriteRule ^([^.]+)$ $1.html [QSA]  
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteRule ^(.\*)$ ruby\_handler.fcgi [QSA,L]

**ruby\_handler.fcgi** is:

> #!/bin/dash  
> #export GEM\_HOME=“$HOME/.gem/ruby/2.3.0/”  
> #export GEM\_PATH=“$GEM\_HOME:/usr/lib/ruby/gems/2.3.0”
> 
> export HOME=“/usr/home/admin”  
> export GEM\_HOME=“$HOME/.gem/ruby/”  
> export GEM\_PATH=“/usr/home/admin/.gem/ruby/2.3.0/”
> 
> exec /usr/bin/ruby /usr/www/users/admin/redmine/startup.rb

**startup.rb** is:

> require\_relative ‘config/environment’
> 
> class Rack::PathInfoRewriter  
> def initialize(app)  
> @app = app  
> end
> 
> def call(env)  
> env.delete(‘SCRIPT\_NAME’)  
> parts = env[‘REQUEST\_URI’].split(‘?’)  
> env[‘PATH\_INFO’] = parts[0]  
> env[‘QUERY\_STRING’] = parts[1].to\_s  
> env[‘HOME’] = “/usr/home/admin/”  
> @app.call(env)  
> end  
> end
> 
> Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(RedmineApp::Application)
