Arquivo da categoria ‘Ruby’

This article shows how you can install Ruby on Rails (RoR) and integrate it in Apache2 on a Debian Etch system (including a short section at the end showing how to use RoR in a web site created with ISPConfig). Ruby on Rails is a web application framework which is rapidly gaining popularity among web programmers. It aims to increase the speed and ease with which database-driven web sites can be created and offers skeleton code frameworks (scaffolding) from the outset. Applications using the RoR framework are developed using the Model-View-Controller design pattern.
Remove ads

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 Preliminary Note

I will use the hostname testapplication.example.com in this tutorial for the virtual host running Ruby on Rails.

2 Installing Ruby And Rails

In order to install Ruby and Ruby on Rails, we simply run

apt-get install ruby libzlib-ruby rdoc irb rubygems rails eruby

3 Installing Apache2 And mod-fcgid

Ruby on Rails can be integrated in Apache2 using mod-fcgid. Therefore we install the following packages:

apt-get install apache2 libapache2-mod-fcgid libfcgi-ruby1.8

Afterwards, we enable a few Apache modules:

a2enmod ssl
a2enmod rewrite
a2enmod suexec
a2enmod include

and reload Apache:

/etc/init.d/apache2 force-reload

4 Installing MySQL And The Ruby MySQL Bindings

Most probably you or your users will like to create database-driven Ruby on Rails applications, therefore we install the MySQL server and the Ruby MySQL bindings now:

apt-get install libmysql-ruby mysql-server

You should set a root password for MySQL now:

mysqladmin -u root password yourrootsqlpassword

If MySQL is listening not only on 127.0.0.1, but on other addresses as well (e.g. server1.example.com), you should set a root password for these addresses as well:

mysqladmin -h server1.example.com -u root password yourrootsqlpassword

5 Creating Our Ruby On Rails Environment

We can now create a directory in which we want to develop our future RoR applications. I’d like to develop them in /var/rails, so I create that directory now:

mkdir /var/rails

Apache2 should have read/write access to that directory, so we make the Apache user (www-data on Debian) and Apache group (again www-data) the owner and group of that directory:

chown -R www-data:www-data /var/rails

Now we can create our first RoR application which we will call testapplication. We will create testapplication under the user www-data so that Apache has read/write access to it:

cd /var/rails
su -m www-data

Now that we’re logged in as www-data, we run

rails testapplication

This will create a directory called testapplication within /var/rails that contains all directories and files we need to develop our RoR application.

Next, we type in

exit

to become the root user again.

6 Modifying Our Application’s .htaccess File

The web folder of testapplication is /var/rails/testapplication/public. It contains an .htaccess file that we must modify so that Apache2 can run RoR applications using mod-fcgid.

vi /var/rails/testapplication/public/.htaccess

Comment out the AddHandler fastcgi-script .fcgi and AddHandler cgi-script .cgi lines and add the line AddHandler fcgid-script .fcgi. Also comment out the line RewriteRule ^(.*)$ dispatch.cgi [QSA,L] and add the line RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] (note that it’s now dispatch.fcgi instead of dispatch.cgi). Afterwards, the file should look like this:
Remove ads

# General Apache options
#AddHandler fastcgi-script .fcgi
#AddHandler cgi-script .cgi
AddHandler fcgid-script .fcgi
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

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
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 “<h2>Application error</h2>Rails application failed to start properly”

7 Creating A Virtual Host For Our RoR Application

(If you use ISPConfig, please go to chapter 8!)

Now it’s time to create an Apache vhost for our application. I will use the hostname testapplication.example.com so that our application can be reached under http://testapplication.example.com (assuming that testapplication.example.com points to the correct IP address).

The easiest way to create such a vhost is to replace the existing default vhost in /etc/apache2/sites-available/default (assuming that this default vhost isn’t needed!):

cp /etc/apache2/sites-available/default /etc/apache2/sites-available/default_old
cat /dev/null > /etc/apache2/sites-available/default
vi /etc/apache2/sites-available/default

<Virtualhost *:80>
ServerName testapplication.example.com
DocumentRoot /var/rails/testapplication/public/

<Directory /var/rails/testapplication/public>
Options ExecCGI FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</Virtualhost>

Of course, instead of replacing the default vhost, you can simply add your testapplication.example.com vhost at the end of /etc/apache2/sites-available/default so that you keep the default vhost.

Now we restart Apache:

/etc/init.d/apache2 restart

Next we open http://testapplication.example.com in a browser. We should see the default RoR page:

That’s it! Now we can start to develop our RoR application in the /var/rails/testapplication directory.

8 RoR And ISPConfig

(If you don’t use ISPConfig, skip this chapter!)

In this chapter I assume that you have created a web site called testapplication.example.com with the document root /var/www/web1/web in ISPConfig, and that your RoR testapplication is still in /var/rails/testapplication.

To make our RoR testapplication available in the testapplication.example.com vhost which we have created in ISPConfig, we do the following:

First, we put the following lines into the Apache Directives field of the testapplication.example.com web site in ISPConfig:

<Directory /var/www/web1/web>
Options +ExecCGI +FollowSymLinks
AllowOverride all
</Directory>

Then we rename /var/rails/testapplication/public to /var/rails/testapplication/web, copy the contents of /var/rails/testapplication to /var/www/web1, and make the Apache user the owner of /var/www/web1/web:

cd /var/rails/testapplication
mv public web
cp -pfr * /var/www/web1
chown www-data:web1 /var/www/web1/web

That’s it. The RoR application should now work in the testapplication.example.com vhost which we have created in ISPConfig.

9 Links

* Ruby on Rails: http://www.rubyonrails.org
* Ruby: http://www.ruby-lang.org
* Debian: http://www.debian.org
* ISPConfig: http://www.ispconfig.org

Anúncios

RadRails

Publicado: outubro 15, 2007 em Rails, Ruby

 RadRails é um IDE para desenvolvimento de aplicações usando Ruby on Rails (RoR),feito sobre o Eclipse IDE.

http://www.radrails.org/

Como o Rails funciona ?

Publicado: outubro 11, 2007 em Desenvolvimento, Rails, Ruby

Rails funciona com um leque de servidores web e bancos de dados. Para o servidor, nós recomendamos Apache ou lighttpd, rodando tanto FastCGI, SCGI, ou Mongrel. Como banco de dados, você pode usar tanto o MySQL quanto PostgreSQL, SQLite, Oracle, SQL Server, DB2, ou Firebird. Qualquer sistema operacional é compatível, embora seja altamente recomendado um baseado em UNIX (Linux, BSD, entre outros) para ambiente de produção.

Se você precisa de hospedagem, veja no wiki internacional do Ruby on Rails uma lista completa de provedores de hospedagem compatíveis com Rails.

Rails é showwww !!!!

Publicado: outubro 11, 2007 em Desenvolvimento, Rails, Ruby

Rails é um framework completo para o desenvolvimento de aplicações web com banco de dados de acordo com o padrão M.V.C. (Model-View-Control). Desde o Ajax na visualização às requisições e respostas no controlador até a abstração de banco de dados no modelador, o Rails permite o desenvolvimento em um ambiente puramente Ruby, sem misturar outras linguagens de programação.
Para botar tudo para funcionar, você só precisa de um banco de dados e um servidor web. Nada mais.

 https://i0.wp.com/blogs.sun.com/portal/resource/rails-podcast.png

Instalando Ruby e Rails

Instalação super simples

apt-get install ruby libzlib-ruby rdoc irb rubygems rails eruby

Instalando o Apache2 e o mod-fcgid

Para integrar o Ruby on Rails  no Apache2 é fundamental o mod-fcgid.

apt-get install apache2 libapache2-mod-fcgid libfcgi-ruby1.8


Agora, habilite os Apache modules:

a2enmod ssl
a2enmod rewrite
a2enmod suexec
a2enmod include

e reload Apache:

/etc/init.d/apache2 force-reload

Instalando MySQL e o  Ruby MySQL Bindings

Existe uma grande probabilidade do uso de base de dados para as suas  Ruby e Rails applications, portando instale o MySQL server e o  Ruby MySQL bindings agora:

apt-get install libmysql-ruby mysql-server

Especifique o  password do root para o MySQL agora:

mysqladmin -u root password suasenhaderootdomysql

Criando – Ruby On Rails Environment

Crie agora  o para o uso futuro de RoR applications. Posso sugerir o diretorio /var/rails, então crie este diretório agora:

mkdir /var/rails

Determinando usuário e grupo do diretório
chown -R www-data:www-data /var/rails

cd /var/rails
su -m www-data

rails testapplication

Modificando o arquivo  .htaccess da sua aplicação.

vi /var/rails/testapplication/public/.htaccess e cole este conteúdo.

# General Apache options
#AddHandler fastcgi-script .fcgi
#AddHandler cgi-script .cgi
AddHandler fcgid-script .fcgi
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

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
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 “<h2>Application error</h2>Rails application failed to start properly”

Criando um Virtual Host para a RoR Application

cp /etc/apache2/sites-available/default /etc/apache2/sites-available/default_old
cat /dev/null > /etc/apache2/sites-available/default
vi /etc/apache2/sites-available/default

<Virtualhost *:80>
ServerName testapplication.example.com
DocumentRoot /var/rails/testapplication/public/

<Directory /var/rails/testapplication/public>
Options ExecCGI FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</Virtualhost>

Agora rstart o apache

/etc/init.d/apache2 restart

Usando o browser digite na barra de endeço.

http://localhost