您的位置:首页 > 编程语言 > Ruby

ubuntu8.10搭建Ruby on Rails环境

2009-05-04 23:36 567 查看
https://help.ubuntu.com/community/RubyOnRails以下为连接中内容,作为备份

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 startfighting like Spock and Captain Kirk in Amok Time. If you haven't seenthat episode, trust me: you don't want that.

Get Ruby

sudo apt-get install ruby-full build-essential

Server Installation

Nowyou have ruby, you already got a server included, WEBrick. You maysettle with that, also because the installation is much easier, andreboots are faster. But it lacks the configuration options that apacheand lighttpd offer. So if you want to have RubyOnRails running onapache 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.tgzcd rubygems-1.1.0sudo ruby setup.rbsudo ln -s /usr/bin/gem1.8 /usr/bin/gemsudo 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.tgzcd rubygems-1.2.0sudo ruby setup.rbsudo ln -s /usr/bin/gem1.8 /usr/bin/gemsudo gem update --systemThe 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/gemIn the file find:require 'rubygems'Add the following line below the above line:require 'rubygems/gem_runner'

RubyGems 1.3.1

wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz tar xzvf rubygems-1.3.1.tgzcd rubygems-1.3.1sudo ruby setup.rbsudo ln -s /usr/bin/gem1.8 /usr/bin/gemsudo gem update --system

Installing rails

We can now use RubyGems to install rails:sudo gem install rails

Preparing for your first rails app

Configurationof the webserver also assumes you have by then a rails application setup. Simply enter to get that done (it will create you a first testpage):Default (sqlite3 backend):rails /home/myuser/www/mynewappFor a mysql back-end:rails /home/myuser/www/mynewapp -d mysqlYouwill see a bunch of stuff on the shell... that should be fine (unlessyou see a error message). That created the rails folder with all thestuff, so now you should have something like have:/home/myuser/www/mynewapp/public

Configure the server

WEBrick (Ruby's server)

Noconfiguring needed, everything is ready to create your firstapplication. You can even try this step before you try launching yourapplication 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=3000Your 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 thedatabase, you might need to install a DB connector, or create adatabase.Install the sqlite3 connector:sudo apt-get install libsqlite3-devsudo gem install sqlite3-rubyOr install the MySQL database and it's connector:sudo apt-get install mysql-server mysql-clientsudo apt-get install libmysql-ruby libmysqlclient-devsudo gem install mysqlOr install the PostgreSQL database and it's connector:sudo apt-get install postgresql-server postgresql-clientsudo apt-get install libpq-devsudo gem install pg

Apache

Run the following to install passenger, an apache module that adds support for running rails apps within apache:sudo gem install passengersudo passenger-install-apache2-moduleNow you have to configure apache to point to the passenger module. Simply copy the following suggested code from the passenger-install-apache2-module installation to the end of your Apache configuration file, which can be accessed by typing in the command sudo gedit /etc/apache2/apache2.conf:(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.soRailsSpawnServer /usr/lib/ruby/gems/1.8/gems/passenger-1.0.3/bin/passenger-spawn-serverRailsRuby /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.soPassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3PassengerRuby /usr/bin/ruby1.8(if you are using RubyGems 1.3.1):LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.soPassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6PassengerRuby /usr/bin/ruby1.8Nowyou should point apache to the location of your Ruby app. Createsomething like this in /etc/apache2/sites-available/ror.myhost.com<VirtualHost *>ServerName ror.myhost.comDocumentRoot /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 fromwith var/www (or wherever you have the root of your apache www folder),e.g.:ln -s /home/myuser/www/mynewapp/public /var/www/mynewappIn case of localhost (which is the default host with a fresh ubuntu/apache install) edit default in /etc/apache2/sites-available and add:RailsBaseURI /mynewappmurb: I had to add RailsEnv developmentas well to get around the 'no route found to match"/rails/info/properties" with {:method=>:get}' warning... (cansomeone elaborate on why?) apparently this is because /info/properties is buggy and no longer supported: http://www.ruby-forum.com/topic/161924Save, and enable the rewrite module for apache, and register this site... and finally, restart apache.sudo a2enmod rewritesudo a2ensite ror.myhost.comsudo /etc/init.d/apache2 restart

Lighttpd

Edit lighttpd.conf, e.g.:sudo kate /etc/lighttpd/lighttpd.confand 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 runsudo /etc/init.d/lighttpd restartand you're set, go to http://localhostand you should see the rails index... click on the link "About yourrails environment" and if you don't see a 404 or 500 error... thenyou're set (you should see either a rails error, or a rails message orsomething like that).

Known Problems

just in case you get a message like this:kmin@metakmin:~/ruby_test$ gem -v1.2.0kmin@metakmin:~/ruby_test$ rails -vRails 2.2.2kmin@metakmin:~/ruby_test$ gem update --systemUpdating RubyGemsNothing to updatekmin@metakmin:~/ruby_test$ script/serverRails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update--system` and try again.kmin@metakmin:~/ruby_test$dont panic, just run:sudo gem install rubygems-updatesudo update_rubygems* thanks to Tomasz Przybysz who mailed me with the problem and then with the solutionfor any comments on the lighttpd install please feel free to mail me to santiago-ve@ubuntu.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: