ãããVPSã«Ruby Enterprise Editionãã¤ã³ã¹ãã¼ã«ãã¦ãRailsã®ãµã³ãã«ã¢ããªãä½æãã
ãããVPS(CentOS)ã«Ruby Enterprise Editionãã¤ã³ã¹ãã¼ã«ããã¨ãã®ã¡ã¢ãREE以å¤ã«ããMySQLãApacheãRailsãã¤ã³ã¹ãã¼ã«ãã¦ããµã³ãã«ãµããªãä½æããã
REEの公式ページã«ããã¨ãREEã¯Phusion Passengerï¼Railsãå®è¡ããããã®Apacheã¢ã¸ã¥ã¼ã«ï¼ã使ã£ãã¨ãã«ãã¡ã¢ãªä½¿ç¨éã33%åæ¸ããããããé常ã®Ruby1.8.7ã¨ã®äºæã100%ã¨ã®ãã¨ã
Ruby Enterprise Editionã®ã¤ã³ã¹ãã¼ã«ã«ã¯ãさくらVPSのCentOSにRuby Enterprise Editionをインストール id: kadoppeさんの記事ãåèã«ããã¦ããã ããã
- Ruby Enterprise Editionã®ã¤ã³ã¹ãã¼ã«
- MySQLã®ã¤ã³ã¹ãã¼ã«
- Apacheã®ã¤ã³ã¹ãã¼ã«
- Railsã®ã¤ã³ã¹ãã¼ã«
- ãµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ã®ä½æ
1. Ruby Enterprise Editionã®ã¤ã³ã¹ãã¼ã«
$ wget http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.03.tar.gz # ãã¡ã¤ã«ããã¦ã³ãã¼ã $ tar zxvf ruby-enterprise-1.8.7-2011.03.tar.gz # ãã¡ã¤ã«ãå±é $ cd ruby-enterprise-1.8.7-2011.03 $ sudo ./installer # ã¤ã³ã¹ãã¼ã©ã¼ãå®è¡ Welcome to the Ruby Enterprise Edition installer This installer will help you install Ruby Enterprise Edition 1.8.7-2011.03. Don't worry, none of your system files will be touched if you don't want them to, so there is no risk that things will screw up. You can expect this from the installation process: 1. Ruby Enterprise Edition will be compiled and optimized for speed for this system. 2. Ruby on Rails will be installed for Ruby Enterprise Edition. 3. You will learn how to tell Phusion Passenger to use Ruby Enterprise Edition instead of regular Ruby. Press Enter to continue, or Ctrl-C to abort. Checking for required software... * C compiler... found at /usr/bin/gcc * C++ compiler... found at /usr/bin/g++ * The 'make' tool... found at /usr/bin/make * The 'patch' tool... found at /usr/bin/patch * Zlib development headers... not found * OpenSSL development headers... not found * GNU Readline development headers... not found Some required software is not installed. But don't worry, this installer will tell you how to install them. Press Enter to continue, or Ctrl-C to abort.
ãå¿ è¦ãªã©ã¤ãã©ãªãå ¥ã£ã¦ãªããï¼ãã¨è¨ãããã®ã§ãã¤ã³ã¹ãã¼ã«ããã
$ sudo -i # yum -y install readline-devel # yum -y install zlib-devel # yum -y install openssl-devel
å度ã¤ã³ã¹ãã¼ã©ã¼ãå®è¡ãéä¸ã§ãã©ã®ãã£ã¬ã¯ããªã«ã¤ã³ã¹ãã¼ã«ãããèãã¦ããã®ã§ã/usr/localã¨å ¥åããã
# ./installer # ã¤ã³ã¹ãã¼ã©ã¼ãå®è¡ ... Where would you like to install Ruby Enterprise Edition to? (All Ruby Enterprise Edition files will be put inside that directory.) [/opt/ruby-enterprise-1.8.7-2011.03] : /usr/local # ããã«å ¥åãã ... ... # mysqlã®gemãã¤ã³ã¹ãã¼ã«ã§ããªãã£ãã¨ããã¨ã©ã¼ -------------------------------------------- Warning: some libraries could not be installed The following gems could not be installed, probably because of an Internet connection error: * mysql These gems are not required, i.e. Ruby Enterprise Edition will work fine without them. But most people use Ruby Enterprise Edition in combination with Phusion Passenger and Ruby on Rails, which do require one or more of the aforementioned gems, so you may want to install them later. To install the aforementioned gems, please use the following commands: * /usr/local/bin/ruby /usr/local/bin/gem install mysql Press ENTER to show the next screen. ... # Phusion Passengerã«ã¤ãã¦ã®æ³¨æäºé -------------------------------------------- Ruby Enterprise Edition is successfully installed! If want to use Phusion Passenger (http://www.modrails.com) in combination with Ruby Enterprise Edition, then you must reinstall Phusion Passenger against Ruby Enterprise Edition, as follows: /usr/local/bin/passenger-install-apache2-module Make sure you don't forget to paste the Apache configuration directives that the installer gives you. # ã¢ã³ã¤ã³ã¹ãã¼ã«æ¹æ³ If you ever want to uninstall Ruby Enterprise Edition, simply remove this directory: /usr/local If you have any questions, feel free to visit our website: http://www.rubyenterpriseedition.com Enjoy Ruby Enterprise Edition, a product of Phusion (www.phusion.nl) :-)
mysqlã®gemãã¤ã³ã¹ãã¼ã«ã§ããªãã£ãã¨åºãã
2. MySQLã®ã¤ã³ã¹ãã¼ã«
mysqlã®gemãã¤ã³ã¹ãã¼ã«ã§ããªãã£ãã®ã¯ãMySQLãã®ãã®ãã¤ã³ã¹ãã¼ã«ããã¦ããªããã¨ãåå ãããããªããã¾ãMySQLãã¤ã³ã¹ãã¼ã«ãã¦ããã«ãã¦ã¿ãã
# yum install mysql-server # MySQLãã¤ã³ã¹ãã¼ã« # /usr/local/bin/ruby /usr/local/bin/gem install mysql # mysqlã®gemãã¤ã³ã¹ãã¼ã« Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension. /usr/local/bin/ruby extconf.rb checking for mysql_ssl_set()... no checking for rb_str_set_len()... no checking for rb_thread_start_timer()... no checking for mysql.h... no checking for mysql/mysql.h... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/bin/ruby --with-mysql-config --without-mysql-config Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection. Results logged to /usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
mysqlã®gemã®ã¤ã³ã¹ãã¼ã«ã§ã¨ã©ã¼ãåºããåå ã¯ããããããªããã mysql-serverã ãã§ã¯è¶³ããªãã£ã½ãã以ä¸ã®ããã«ãmysqlã¨mysql-develãã¤ã³ã¹ãã¼ã«ããã¨ã¨ã©ã¼ãåºãªããªã£ãã
# yum -y mysql mysql-devel ... Complete! # /usr/local/bin/ruby /usr/local/bin/gem install mysql Building native extensions. This could take a while... Successfully installed mysql-2.8.1 # ä»åº¦ã¯æå 1 gem installed Installing ri documentation for mysql-2.8.1... Installing RDoc documentation for mysql-2.8.1...
ä»åº¦ã¯mysqlã®gemãç¡äºã¤ã³ã¹ãã¼ã«ã§ãããã¤ãã§ã«ãMySQLãèµ·åãã¦ããã
# /etc/rc.d/init.d/mysqld start # ãµã¼ãã¹ãèµ·å # /sbin/chkconfig mysqld on # MySQLã®èªåèµ·åãONã«ãã
3. Apacheã®ã¤ã³ã¹ãã¼ã«
Apacheãã¾ã ã¤ã³ã¹ãã¼ã«ãã¦ããªãã£ããã¤ã³ã¹ãã¼ã«ãããさくらVPS設定その2 Apache+MySQL+WordPress id:r7kamuraさんã®è¨äºãåèã«ãªãã
4. Railsã®ã¤ã³ã¹ãã¼ã«
ææ°çã®Railsãã¤ã³ã¹ãã¼ã«ããã
$ sudo gem install rails --no-rdoc # ããã¥ã¡ã³ãä¸è¦ -bash: gem: command not found
ãã£ã¨ãgemã«ãã¹ãéã£ã¦ããªãããè¦ã¤ãããªããããã¾ã§ã®ããã«æ¯åãã«ãã¹ãå ¥åããã®ã¯é¢åãªã®ã§ã以ä¸ã®ããã«bashã®è¨å®ãã¡ã¤ã«ã«ãã¹ãæ¸ãè¾¼ããさくらVPS設定その1 User+SSH+Firewall id:r7kamuraさんã®è¨äºãåèã«ãªãã
$ vi ~/.bash_profile # ãã¡ã¤ã«ãç·¨éãã PATH=$PATH:$HOME/bin # ãã®è¡ã®å¾ã«... PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin # ãã®è¡ã追å # ã:wqãã§ä¿åå¾ã以ä¸ã®ã³ãã³ãã§è¨å®ãåèªã¿è¾¼ã¿ããã $ source ~/.bash_profile
ããããã¦railsãã¤ã³ã¹ãã¼ã«ã
$ sudo gem install rails --no-rdoc # ããã¥ã¡ã³ãä¸è¦
iptablesï¼ãã¡ã¤ã¤ã¼ã¦ã©ã¼ã«ï¼ã§Railsã®ãã¼ããéãã¦ããªãå ´åã¯ã以ä¸ã®ã³ãã³ãã§è¨å®ãã¦ããã
$ sudo vi /etc/sysconfig/iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT # 追å $ sudo /etc/rc.d/init.d/iptables restart # åèµ·å $ sudo sudo iptables -L # è¨å®ã®ç¢ºèª
5. ãµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ã®ä½æ
ãµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ãä½ã£ã¦å®è¡ãã¦ã¿ãã
$ mkdir ~/workspace # ãã¼ã ãã£ã¬ã¯ããªã«workspaceãã©ã«ããä½ã $ cd ~/workspace $ rails new demo -d mysql # DBãæå®ãã¦ã¢ããªã±ã¼ã·ã§ã³ãæ°è¦ä½æ ... run bundle install Enter your password to install the bundled RubyGems to your system:
ã足ããªãgemãã¤ã³ã¹ãã¼ã«ãããããã¹ã¯ã¼ãå ¥ãã¦ããã¨è¨ãããã®ã§ããã°ã¤ã³ã¦ã¼ã¶ã¼ã®ãã¹ã¯ã¼ããå ¥åãããããã¨ã以ä¸ã®ããã«ããããã¤ã³ã¹ãã¼ã«ãã¦ãããã
.. Installing coffee-script-source (1.1.3) Installing execjs (1.2.9) Installing coffee-script (2.2.0) ... Installing coffee-rails (3.1.1) Installing jquery-rails (1.0.17) Installing mysql2 (0.3.10) with native extensions ... Installing sass (3.1.10) Installing sass-rails (3.1.4) Installing uglifier (1.0.4) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
ã¨ããããããã¢ã¢ããªã«å¿ è¦ãªæºåãããã
$ rails generate scaffold Post name:string title:string content:text # Postã¨ããååã®ã¢ãã«ããã¥ã¼ãã³ã³ããã¼ã©ã¼ãä½æ $ rake db:create # DBãä½æ $ rake db:migrate # ãã¼ãã«ãä½æ $ rake routes # URLã®ã«ã¼ãã£ã³ã°ã確èªï¼/postsã«ã¢ã¯ã»ã¹ããã°ãããã¨ããããï¼ posts GET /posts(.:format) {:action=>"index", :controller=>"posts"} POST /posts(.:format) {:action=>"create", :controller=>"posts"} new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"} edit_post GET /posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"} post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"} PUT /posts/:id(.:format) {:action=>"update", :controller=>"posts"} DELETE /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}
ä½æããã¢ããªã±ã¼ã·ã§ã³ã®ã«ã¼ããã£ã¬ã¯ããªã§ãµã¼ãã¼ãèµ·åããã
$ rails server /usr/local/lib/ruby/gems/1.8/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from /usr/local/lib/ruby/gems/1.8/gems/execjs-1.2.9/lib/execjs.rb:5 from /usr/local/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require' from /usr/local/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee_script.rb:1 from /usr/local/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require' from /usr/local/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee-script.rb:1 from /usr/local/lib/ruby/gems/1.8/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `require' from /usr/local/lib/ruby/gems/1.8/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1 from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require' from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require' from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each' from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `require' from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each' from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require' from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler.rb:122:in `require' from /home/montecut/workspace/demo/config/application.rb:7 from /usr/local/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/commands.rb:52:in `require' from /usr/local/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/commands.rb:52 from /usr/local/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/commands.rb:49:in `tap' from /usr/local/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/commands.rb:49 from script/rails:6:in `require' from script/rails:6
ã¨ã©ã¼ãåºããRails 3.1 execjs and Could not find a JavaScript runtimeã®ãã¼ã¸ã«ããã¨ãJavaScriptã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ããã¨è§£æ±ºããã¨ã®ãã¨ãGemfileã«gemã追è¨ãã¦ãbundle installã³ãã³ãã§è¶³ããªãgemãã¤ã³ã¹ãã¼ã«ããã
$ vi Gemfile # ã¢ããªã±ã¼ã·ã§ã³ã®ã«ã¼ãç´ä¸ã«ããGemfileãç·¨é gem 'execjs' # 追å gem 'therubyracer' # 追å $ bundle install # 足ããªãgemãå ¥ãã¦ããã $ rails server # å度ãµã¼ãã¼ãèµ·å
ãµã¼ãã¼ãèµ·åãããããªã®ã§ããã©ã¦ã¶ãã確èªãhttp://wwwXXXXXX.sakura.ne.jp:3000/postsãéãã¦ãdemoã¢ããªã±ã¼ã·ã§ã³ã®ç»é¢ã表示ãããã®ã§ããã§OKã