firstruby

Master ruby with us

Deploying Rails application with Apache on Windows XP

Posted by firstruby on March 21, 2007

We can run rails application with default WEBrick server, lighttpd, mongrel, apache.

Here we ll go for deploying rails with apache.

1. Install Ruby and Rails.

2. Install Apache HTTP Server.

3. Get FastCGI2.4.2

4. Download RubyForApache

5. Install MySQL

6. Rename mod_fastcgi-2.4.2-AP20.dll to mod_fastcgi.dll and copy it to the Apache modules folder (default is c:\programs files\Apache Group\Apache2\modules).

7. Install Ruby For Apache for all options. It will give error, but just ignore and continue.

8. Copy fcgi.so and mysql.so from  /RubyForApache/lib/ruby/site_ruby/1.8/i386-msvcrt to Apache modules folder (default is c:\programs files\Apache Group\Apache2\modules).

Apache Configuraration,

Edit the Apache httpd.conf Configuration File,

Check for

#LoadModule rewrite_module modules/mod_rewrite.so

and change it to

LoadModule rewrite_module modules/mod_rewrite.so

Then add following line,

LoadModule fastcgi_module modules/mod_fastcgi.dll

Now at the bottom of this file, add following,

<VirtualHost *:4000>
ServerName rails
DocumentRoot “C:/testing/public”
<Directory “C:/testing/public/”>
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny
AddHandler cgi-script .cgi
AddHandler fastcgi-script .fcgi
</Directory>
</VirtualHost>

(set paths according to your application)

Configure your Rails application,

1. Go to the public folder in your Rails application and open .htaccess

2. Look for line like  RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

Change it to RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

3. Now restart your Apache.

4. Access http://localhost:4000

It will show Welcome page (index.html) of Rails.

Advertisements

8 Responses to “Deploying Rails application with Apache on Windows XP”

  1. […] ที่มา:https://firstruby.wordpress.com/2007/03/21/deploying-rails-with-apache-on-windows-xp/ เพิ่มเติม: […]

  2. bob said

    G0KV7n hi nice site thanx http://peace.com

  3. Viet Trung said

    Thank you very much for a useful article.

    Coming along with your guide, I can see the Welcome page (http://localhost:80) of Rails.

    However, when I try to access any page in my application, e.g., at http://localhost:80/main, I get the error 404 “The webpage cannot be found”. (I am sure the application works with WebBrick.)

    One more thing, I could not find the file .htaccess in my application’s public directory, and so I could not set the param RewriteRule. May it cause the error?

    If so how can I fix this?

    I am thankful if you could give me any suggestion.

    Thanks and regards.

  4. firstruby said

    @Viet Trung,

    If there is no .htacces file in /public folder, then you can create the .htaccess file in the /public folder, and write following in that file,

    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

    Thanks,
    FirstRuby

  5. Viet Trung said

    Hi firstruby,

    Thank you very much for your reply.

    I had done as you said. The 404 error does not show up anymore. Instead of that, however, the webpage shows the content of dispatch.fcgi in plain text, something like:

    ————–
    #!C:/Program Files/NetBeans 6.5.1/ruby2/jruby-1.1.4/bin/jruby.bat
    #
    # You may specify the path to the FastCGI crash log (a log of unhandled
    # exceptions which forced the FastCGI instance to exit, great for debugging)
    # and the number of requests to process before running garbage collection.

    ————–

    I would like to show you here the content of my .htaccess in my application /public:

    —————–
    # General Apache options
    AddHandler fcgid-script .fcgi
    AddHandler cgi-script .cgi
    #Options +FollowSymLinks +ExecCGI

    # If you don’t want Rails to look in certain directories,
    # use the following rewrite rules so that Apache won’t rewrite certain requests
    #
    # Example:
    # RewriteCond %{REQUEST_URI} ^/notrails.*
    # RewriteRule .* – [L]

    # Redirect all requests not available on the filesystem to Rails
    # By default the cgi dispatcher is used which is very slow
    #
    # For better performance replace the dispatcher with the fastcgi one
    #
    # Example:
    # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    RewriteEngine On

    # If your Rails application is accessed via an Alias directive,
    # then you MUST also set the RewriteBase in this htaccess file.
    #
    # Example:
    # Alias /myrailsapp /path/to/myrailsapp/public
    # RewriteBase /myrailsapp

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

    # In case Rails experiences terminal errors
    # Instead of displaying this message you can supply a file here which will be rendered instead
    #
    # Example:
    # ErrorDocument 500 /500.html

    ErrorDocument 500 “Application errorRails application failed to start properly”
    —————–

    I check Apache’s error log file, but there are only notices, no error found. I don’t know what to do further.

    Please let me know if you have any suggestion. If you need any information to detect the problem, please let me know.

    Many thanks and best regards,

    .Viet Trung.

    • firstruby said

      @Viet Trung,

      I don’t think there is any issue in your .htaccess file.

      Did you restart the FCGI processes ? You can Restart your FCGI Processes at the shell prompt using following command,

      pkill -9 -u username -f dispatch.fcgi

      Thanks,
      FirstRuby

  6. giangnd said

    @Viet Trung it’s great you successfully configure Apache and SVN. I got “Forbidden” error!

  7. Bruna said

    Bruna…

    […]Deploying Rails application with Apache on Windows XP « firstruby[…]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: