特殊:Badtitle/NS100:RubyOnRails
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/RubyOnRails }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/af | • {{#if: UbuntuHelp:RubyOnRails|Afrikaans| [[::RubyOnRails/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/ar | • {{#if: UbuntuHelp:RubyOnRails|العربية| [[::RubyOnRails/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/az | • {{#if: UbuntuHelp:RubyOnRails|azərbaycanca| [[::RubyOnRails/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/bcc | • {{#if: UbuntuHelp:RubyOnRails|جهلسری بلوچی| [[::RubyOnRails/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/bg | • {{#if: UbuntuHelp:RubyOnRails|български| [[::RubyOnRails/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/br | • {{#if: UbuntuHelp:RubyOnRails|brezhoneg| [[::RubyOnRails/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/ca | • {{#if: UbuntuHelp:RubyOnRails|català| [[::RubyOnRails/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/cs | • {{#if: UbuntuHelp:RubyOnRails|čeština| [[::RubyOnRails/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/de | • {{#if: UbuntuHelp:RubyOnRails|Deutsch| [[::RubyOnRails/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/el | • {{#if: UbuntuHelp:RubyOnRails|Ελληνικά| [[::RubyOnRails/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/es | • {{#if: UbuntuHelp:RubyOnRails|español| [[::RubyOnRails/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/fa | • {{#if: UbuntuHelp:RubyOnRails|فارسی| [[::RubyOnRails/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/fi | • {{#if: UbuntuHelp:RubyOnRails|suomi| [[::RubyOnRails/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/fr | • {{#if: UbuntuHelp:RubyOnRails|français| [[::RubyOnRails/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/gu | • {{#if: UbuntuHelp:RubyOnRails|ગુજરાતી| [[::RubyOnRails/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/he | • {{#if: UbuntuHelp:RubyOnRails|עברית| [[::RubyOnRails/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/hu | • {{#if: UbuntuHelp:RubyOnRails|magyar| [[::RubyOnRails/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/id | • {{#if: UbuntuHelp:RubyOnRails|Bahasa Indonesia| [[::RubyOnRails/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/it | • {{#if: UbuntuHelp:RubyOnRails|italiano| [[::RubyOnRails/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/ja | • {{#if: UbuntuHelp:RubyOnRails|日本語| [[::RubyOnRails/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/ko | • {{#if: UbuntuHelp:RubyOnRails|한국어| [[::RubyOnRails/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/ksh | • {{#if: UbuntuHelp:RubyOnRails|Ripoarisch| [[::RubyOnRails/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/mr | • {{#if: UbuntuHelp:RubyOnRails|मराठी| [[::RubyOnRails/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/ms | • {{#if: UbuntuHelp:RubyOnRails|Bahasa Melayu| [[::RubyOnRails/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/nl | • {{#if: UbuntuHelp:RubyOnRails|Nederlands| [[::RubyOnRails/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/no | • {{#if: UbuntuHelp:RubyOnRails|norsk| [[::RubyOnRails/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/oc | • {{#if: UbuntuHelp:RubyOnRails|occitan| [[::RubyOnRails/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/pl | • {{#if: UbuntuHelp:RubyOnRails|polski| [[::RubyOnRails/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/pt | • {{#if: UbuntuHelp:RubyOnRails|português| [[::RubyOnRails/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/ro | • {{#if: UbuntuHelp:RubyOnRails|română| [[::RubyOnRails/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/ru | • {{#if: UbuntuHelp:RubyOnRails|русский| [[::RubyOnRails/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/si | • {{#if: UbuntuHelp:RubyOnRails|සිංහල| [[::RubyOnRails/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/sq | • {{#if: UbuntuHelp:RubyOnRails|shqip| [[::RubyOnRails/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/sr | • {{#if: UbuntuHelp:RubyOnRails|српски / srpski| [[::RubyOnRails/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/sv | • {{#if: UbuntuHelp:RubyOnRails|svenska| [[::RubyOnRails/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/th | • {{#if: UbuntuHelp:RubyOnRails|ไทย| [[::RubyOnRails/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/tr | • {{#if: UbuntuHelp:RubyOnRails|Türkçe| [[::RubyOnRails/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/vi | • {{#if: UbuntuHelp:RubyOnRails|Tiếng Việt| [[::RubyOnRails/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/yue | • {{#if: UbuntuHelp:RubyOnRails|粵語| [[::RubyOnRails/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/zh | • {{#if: UbuntuHelp:RubyOnRails|中文| [[::RubyOnRails/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/zh-hans | • {{#if: UbuntuHelp:RubyOnRails|中文(简体)| [[::RubyOnRails/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:RubyOnRails | UbuntuHelp:RubyOnRails | {{#if: | :}}RubyOnRails}}/zh-hant | • {{#if: UbuntuHelp:RubyOnRails|中文(繁體)| [[::RubyOnRails/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:RubyOnRails|:RubyOnRails|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :RubyOnRails/zh | | {{#ifexist: RubyOnRails/zh | | {{#ifeq: {{#titleparts:RubyOnRails|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:RubyOnRails|1|-1|}} | zh | | }}
Intro
These instructions are for Ubuntu 8.04 LTS (hardy). Instead of using apt
we use gems because of what ReinH put best...
<ReinH> Let gems manage your rails package otherwise gem and apt-get will start fighting like Spock and Captain Kirk in Amok Time. If you haven't seen that episode, trust me: you don't want that.
Get Ruby
sudo apt-get install ruby-full build-essential
Server Installation
Now you have Ruby, you already got a server included, WEBrick. You may settle with that, also because the installation is much easier, and reboots are faster. But it lacks the configuration options that apache and lighttpd offer. So if you want to have RubyOnRails running on apache or lighttpd, make sure you have installed these first.
Apache
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
Lighttpd
Preparing the house:
sudo apt-get install lighttpd libfcgi-ruby1.8
Installing RubyGems
The link below is to a specific version of RubyGems (version 1.1). You can get a later version from http://rubyforge.org/frs/?group_id=126, but it should not be really necessary because we ask rubygems to update itself at the end. But to make it more complete, a description of RubyGems 1.2 is also included, below the install instructions of RubyGems 1.2.
RubyGems 1.1.0
wget http://rubyforge.org/frs/download.php/34638/rubygems-1.1.0.tgz tar xzvf rubygems-1.1.0.tgz cd rubygems-1.1.0 sudo ruby setup.rb sudo ln -s /usr/bin/gem1.8 /usr/bin/gem sudo gem update --system
RubyGems 1.2.0
wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz tar xzvf rubygems-1.2.0.tgz cd rubygems-1.2.0 sudo ruby setup.rb sudo ln -s /usr/bin/gem1.8 /usr/bin/gem sudo gem update --system
The below error is sometimes encountered after running sudo gem update --system.
/usr/bin/gem:23: uninitialized constant Gem::GemRunner (NameError)
To fix that error follow the below instructions.
sudo gedit /usr/bin/gem In the file find: require 'rubygems' Add the following line below the above line: require 'rubygems/gem_runner'
Installing rails
We can now use RubyGems to install rails:
sudo gem install rails
Preparing for your first rails app
Configuration of the webserver also assumes you have by then a rails application set up. Simpy enter to get that done (it will create you a first test page:
rails /home/myuser/www/mynewapp
You will see a bunch of stuff on the shell... that should be fine (unless you see a error message). that created the rails folder with all the stuff, so now you should have something like have: /home/myuser/www/mynewapp/public
Configure the server
WebTrick (Ruby's server)
No configuring needed, everything is ready to create your first application. You can even try this step before you try launching your application via apache or lighttpd:
$cd /home/myuser/www/mynewapp $ruby script/server => Booting WEBrick... => Rails 2.1.0 application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2008-07-28 04:39:17] INFO WEBrick 1.3.1 [2008-07-28 04:39:17] INFO ruby 1.8.6 (2007-09-24) [2008-07-28 04:39:17] INFO WEBrick::HTTPServer#start: pid=6860 port=3000
Your application is now responding at `http://0.0.0.0:3000`; press Ctrl+C to stop the web server. If you get errors related to the database, you might want to instal sqlite, or create a database using
Apache
Run the following to install passenger, an apache module that adds support for running rails apps within apache:
sudo gem install passenger sudo passenger-install-apache2-module
Now you have to configure apache to point to the passenger module. Simply copy the suggested code from the passenger-install-apache2-module
installation to your apache configuration file, which should be something along the lines of:
(if you are using RubyGems 1.1):
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-1.0.3/ext/apache2/mod_passenger.so RailsSpawnServer /usr/lib/ruby/gems/1.8/gems/passenger-1.0.3/bin/passenger-spawn-server RailsRuby /usr/bin/ruby1.8
(if you are using RubyGems 1.2):
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3 PassengerRuby /usr/bin/ruby1.8
Now you should point apache to the location of your ruby app. Create something like this in /etc/apache2/sites-available/ror.myhost.com
<VirtualHost *> ServerName ror.myhost.com DocumentRoot /home/myuser/www/mynewapp/public </VirtualHost>
Alternatively, you could run rails in a specific sub uri of your current host, e.g. localhost. First, make a symbolic link to your rails public folder from with var/www (or wherever you have the root of your apache www folder), e.g.:
ln -s /home/myuser/www/mynewapp/public /var/www/mynewapp
In case of localhost (which is the default host with a fresh ubuntu/apache install) edit default
in /etc/apache2/sites-available
and add:
RailsBaseURI /mynewapp
murb: I had to add RailsEnv development
as well to get around the 'no route found to match "/rails/info/properties" with {:method=>:get}' warning... (can someone elaborate on why?)
Save, and enable the rewrite module for apache, and register this site... and finally, restart apache.
sudo a2enmod rewrite sudo a2ensite ror.myhost.com sudo /etc/init.d/apache2 restart
Lighttpd
Edit lighttpd.conf, e.g.:
sudo kate /etc/lighttpd/lighttpd.conf
and here starts the tricky part, paste at the end of the file:
server.modules += ( "mod_fastcgi", "mod_rewrite" ) $HTTP["host"] == "localhost" { server.document-root = "/home/santiago/proyectos/beholder/public/" server.dir-listing = "disable" server.error-handler-404 = "/dispatch.fcgi" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 1, "max-procs" => 1, "socket" => "/tmp/ruby-beholder.socket", "bin-path" => "/home/santiago/proyectos/beholder/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "development" ) ) ) ) }
now run
sudo /etc/init.d/lighttpd restart
and you're set, go to http://localhost and you should see the rails index... click on the link "About your rails enviroment" and if you dont see a 404 o 500 error... then your're set (you should see either a rails error, or a rails message or something like that) for any comments on the lighttpd install please feel free to mail me to [email protected]