[size=medium][b](1)安装Rails[/b][/size]
[b]1)安装需要的Package[/b]
[color=blue]# yum -y install gcc
# yum -y install gcc-c++
# yum -y install zlib zlib-devel
# yum -y install readline readline-devel
# yum -y install openssl openssl-devel[/color]
最好是 [color=blue]#yum install gcc gcc-c++ openssl* readline* ncurses* zlib* libxml* libjpeg* libpng* libxslt* libtool*[/color]
[b]2)安装Ruby[/b]
[color=blue]# cd /usr/local/src
# wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
# tar zxvf ruby-2.0.0-p247.tar.gz
# cd ruby-2.0.0-p247
# ./configure
# make
# make install
# ruby -v[/color]
[b]3)更新Gem[/b]
[color=blue]# gem update --system
# gem -v[/color]
[b]4)安装Rails[/b]
[color=blue]# gem install rdoc
# gem install rails
# rails -v[/color]
[b]5)卸载Ruby[/b]
[color=blue]# cd /usr/local/src/ruby-2.0.0-p247
# cat .installed.list | xargs rm[/color]
[color=red][b]常见问题[/b][/color]
1)问题1(NoMethodError:openssl)
[quote]# gem update --system
ERROR: Loading command: update (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass[/quote]
[color=blue]# cd /usr/local/src/ruby-2.0.0-p247/ext/openssl/
# ruby extconf.rb
# make
# make install[/color]
2)问题2(NoMethodError:zlib)
[quote]# gem update --system
ERROR: Loading command: update (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass[/quote]
[color=blue]# cd /usr/local/src/ruby-2.0.0-p247/ext/zlib/
# ruby extconf.rb
# make
# make install[/color]
[size=medium][b](2)Apache+Passenger[/b][/size]
[b]1)安装Passenger[/b]
[color=blue]# gem install passenger[/color]
[b]2)安装Passenger的Apache模块[/b]
[color=blue]# passenger-install-apache2-module[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/4454/fdf79a17-8cf4-32c8-93f7-0744a104d8ff.png[/img]
缺什么装什么
[color=blue]# yum install gcc-c++
# yum install curl-devel
# yum install httpd-devel
# yum install apr-devel
# yum install apr-util-devel[/color]
如果是通过源码安装的Apache,会提示以下错误:
[quote]* Checking for Apache 2 development headers...
Found: no
* Checking for Apache Portable Runtime (APR) development headers...
Found: no
* Checking for Apache Portable Runtime Utility (APU) development headers...
Found: no[/quote]
[quote]export APXS2=/usr/local/apache2/bin/apxs
export PATH=/usr/local/apache2/bin:$PATH[/quote]
再次执行
[color=blue]# passenger-install-apache2-module[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/4456/1da28726-1bb6-3e7c-b312-c4aaa5b2d9e4.png[/img]
[b]3)设置Apache[/b]
/etc/httpd/conf/httpd.conf
[quote]#Passenger
LoadModule passenger_module /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.7/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.7
PassengerDefaultRuby /usr/local/bin/ruby[/quote]
/etc/httpd/conf.d/rails.conf
[quote]<VirtualHost *:80>
ServerName localhost:80
DocumentRoot /var/www/rails/testapp/public
<Directory /var/www/rails/testapp/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
[/quote]
[b]4)创建Rails工程[/b]
[color=blue]# cd /var/www/rails
# rails new testapp
# bundle install[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/4458/09749d11-ea8d-353c-a65c-ecc0732d1cb3.png[/img]
[color=blue]# yum install sqlite-devel
# cd testapp/
# bundle install[/color]
[b]5)创建Scaffold[/b]
[color=blue]# rails g scaffold friend name:string address:string
# rake db:create RAILS_ENV=production
# rake db:migrate RAILS_ENV=production
# rake assets:precompile RAILS_ENV=production[/color]
[b]6)启动服务[/b]
[color=blue]# setenforce 0
# /etc/init.d/httpd restart[/color]
http://localhost/friends
[img]http://dl2.iteye.com/upload/attachment/0088/4460/726de7ef-b2c2-3b32-a08e-46a2ae863240.png[/img]
[size=medium][b](3)Nginx+Unicorn[/b][/size]
[b]1)安装Nginx[/b]
[color=blue]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# yum install nginx
# /etc/init.d/nginx start[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/4478/53d780c3-246c-352d-a556-83ade3f6d219.png[/img]
[b]2)安装unicorn[/b]
[color=blue]# gem install unicorn[/color]
[b]3)创建测试工程[/b]
省略,和以上步骤相同
[b]4)设置Unicorn[/b]
[color=blue]# cd /var/www/rails/testapp/config/
# wget -O unicorn.rb https://raw.github.com/defunkt/unicorn/master/examples/unicorn.conf.rb
[/color]
修改模板文件,并创建相应的文件夹
config/unicorn.rb
[img]http://dl2.iteye.com/upload/attachment/0088/4480/3bf38cb9-f192-3e27-86cf-0f0e6ac32e2e.png[/img]
[b]5)启动服务[/b]
[color=blue]# unicorn_rails -c config/unicorn.rb -E production -p 5000 -D
# /etc/init.d/nginx restart[/color]
http://localhost:5000/friends
[img]http://dl2.iteye.com/upload/attachment/0088/4484/98abec41-74b5-3d34-8f02-ea67bf3497f0.png[/img]
[b]6)设置Ngnix[/b]
/etc/nginx/nginx.conf
[img]http://dl2.iteye.com/upload/attachment/0088/4486/a6cd2ae3-a65b-3850-a43b-9c8cb4f71753.png[/img]
http://localhost/friends
[img]http://dl2.iteye.com/upload/attachment/0088/4488/92031686-f565-3cf0-92dc-c51501cbc1db.png[/img]
[color=red][b]常见问题[/b][/color]
1)问题1(Could not find a JavaScript runtime.)
将CoffeeScript编译成JavaScript需要JavaScript的runtime,
不像Windows或Mac OS X 默认已经有Javascript引擎,Linux下需要安装。
[color=blue]# gem install execjs
# gem install therubyracer[/color]
实际是libv8,也可以安装nodejs。JRuby用户更多的使用therubyrhino
2)问题排查2(PassengerWatchdog: Permission denied.)
开启SELinux
[color=blue]# setenforce 0[/color]
3)问题排查3(SQLite3::ReadOnlyException:attempt to write a readonly database)
SQLite的数据库文件权限不足
[color=blue]# chmod 777 /db
# chmod 777 databasefilename
# chown user.user databasefilename[/color]
[b]1)安装需要的Package[/b]
[color=blue]# yum -y install gcc
# yum -y install gcc-c++
# yum -y install zlib zlib-devel
# yum -y install readline readline-devel
# yum -y install openssl openssl-devel[/color]
最好是 [color=blue]#yum install gcc gcc-c++ openssl* readline* ncurses* zlib* libxml* libjpeg* libpng* libxslt* libtool*[/color]
[b]2)安装Ruby[/b]
[color=blue]# cd /usr/local/src
# wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
# tar zxvf ruby-2.0.0-p247.tar.gz
# cd ruby-2.0.0-p247
# ./configure
# make
# make install
# ruby -v[/color]
[b]3)更新Gem[/b]
[color=blue]# gem update --system
# gem -v[/color]
[b]4)安装Rails[/b]
[color=blue]# gem install rdoc
# gem install rails
# rails -v[/color]
[b]5)卸载Ruby[/b]
[color=blue]# cd /usr/local/src/ruby-2.0.0-p247
# cat .installed.list | xargs rm[/color]
[color=red][b]常见问题[/b][/color]
1)问题1(NoMethodError:openssl)
[quote]# gem update --system
ERROR: Loading command: update (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass[/quote]
[color=blue]# cd /usr/local/src/ruby-2.0.0-p247/ext/openssl/
# ruby extconf.rb
# make
# make install[/color]
2)问题2(NoMethodError:zlib)
[quote]# gem update --system
ERROR: Loading command: update (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass[/quote]
[color=blue]# cd /usr/local/src/ruby-2.0.0-p247/ext/zlib/
# ruby extconf.rb
# make
# make install[/color]
[size=medium][b](2)Apache+Passenger[/b][/size]
[b]1)安装Passenger[/b]
[color=blue]# gem install passenger[/color]
[b]2)安装Passenger的Apache模块[/b]
[color=blue]# passenger-install-apache2-module[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/4454/fdf79a17-8cf4-32c8-93f7-0744a104d8ff.png[/img]
缺什么装什么
[color=blue]# yum install gcc-c++
# yum install curl-devel
# yum install httpd-devel
# yum install apr-devel
# yum install apr-util-devel[/color]
如果是通过源码安装的Apache,会提示以下错误:
[quote]* Checking for Apache 2 development headers...
Found: no
* Checking for Apache Portable Runtime (APR) development headers...
Found: no
* Checking for Apache Portable Runtime Utility (APU) development headers...
Found: no[/quote]
[quote]export APXS2=/usr/local/apache2/bin/apxs
export PATH=/usr/local/apache2/bin:$PATH[/quote]
再次执行
[color=blue]# passenger-install-apache2-module[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/4456/1da28726-1bb6-3e7c-b312-c4aaa5b2d9e4.png[/img]
[b]3)设置Apache[/b]
/etc/httpd/conf/httpd.conf
[quote]#Passenger
LoadModule passenger_module /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.7/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.7
PassengerDefaultRuby /usr/local/bin/ruby[/quote]
/etc/httpd/conf.d/rails.conf
[quote]<VirtualHost *:80>
ServerName localhost:80
DocumentRoot /var/www/rails/testapp/public
<Directory /var/www/rails/testapp/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
[/quote]
[b]4)创建Rails工程[/b]
[color=blue]# cd /var/www/rails
# rails new testapp
# bundle install[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/4458/09749d11-ea8d-353c-a65c-ecc0732d1cb3.png[/img]
[color=blue]# yum install sqlite-devel
# cd testapp/
# bundle install[/color]
[b]5)创建Scaffold[/b]
[color=blue]# rails g scaffold friend name:string address:string
# rake db:create RAILS_ENV=production
# rake db:migrate RAILS_ENV=production
# rake assets:precompile RAILS_ENV=production[/color]
[b]6)启动服务[/b]
[color=blue]# setenforce 0
# /etc/init.d/httpd restart[/color]
http://localhost/friends
[img]http://dl2.iteye.com/upload/attachment/0088/4460/726de7ef-b2c2-3b32-a08e-46a2ae863240.png[/img]
[size=medium][b](3)Nginx+Unicorn[/b][/size]
[b]1)安装Nginx[/b]
[color=blue]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# yum install nginx
# /etc/init.d/nginx start[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/4478/53d780c3-246c-352d-a556-83ade3f6d219.png[/img]
[b]2)安装unicorn[/b]
[color=blue]# gem install unicorn[/color]
[b]3)创建测试工程[/b]
省略,和以上步骤相同
[b]4)设置Unicorn[/b]
[color=blue]# cd /var/www/rails/testapp/config/
# wget -O unicorn.rb https://raw.github.com/defunkt/unicorn/master/examples/unicorn.conf.rb
[/color]
修改模板文件,并创建相应的文件夹
config/unicorn.rb
[img]http://dl2.iteye.com/upload/attachment/0088/4480/3bf38cb9-f192-3e27-86cf-0f0e6ac32e2e.png[/img]
[b]5)启动服务[/b]
[color=blue]# unicorn_rails -c config/unicorn.rb -E production -p 5000 -D
# /etc/init.d/nginx restart[/color]
http://localhost:5000/friends
[img]http://dl2.iteye.com/upload/attachment/0088/4484/98abec41-74b5-3d34-8f02-ea67bf3497f0.png[/img]
[b]6)设置Ngnix[/b]
/etc/nginx/nginx.conf
[img]http://dl2.iteye.com/upload/attachment/0088/4486/a6cd2ae3-a65b-3850-a43b-9c8cb4f71753.png[/img]
http://localhost/friends
[img]http://dl2.iteye.com/upload/attachment/0088/4488/92031686-f565-3cf0-92dc-c51501cbc1db.png[/img]
[color=red][b]常见问题[/b][/color]
1)问题1(Could not find a JavaScript runtime.)
将CoffeeScript编译成JavaScript需要JavaScript的runtime,
不像Windows或Mac OS X 默认已经有Javascript引擎,Linux下需要安装。
[color=blue]# gem install execjs
# gem install therubyracer[/color]
实际是libv8,也可以安装nodejs。JRuby用户更多的使用therubyrhino
2)问题排查2(PassengerWatchdog: Permission denied.)
开启SELinux
[color=blue]# setenforce 0[/color]
3)问题排查3(SQLite3::ReadOnlyException:attempt to write a readonly database)
SQLite的数据库文件权限不足
[color=blue]# chmod 777 /db
# chmod 777 databasefilename
# chown user.user databasefilename[/color]